-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
saveDetectionMeasurements issue in batch mode #136
Comments
Just to get things started, you do not need to select anything before saving! I always have those two commands at the end of my scripts, and they are not related to what has been selected, it is just a full list of everything that shows up when you look in "Show detection measurements" or "Show annotation measurements" in the Measure menu. I wonder if you remove the selectDetections if maybe that will help things, since selecting all of the detections might cause a slowdown that messes up the save measurements command. You also might try the guiscript=true command at the top of your script, which seems to help some of the cases where the script doesn't allow a command to finish before trying the next one. Is it generating one file for every slide image? The only issues I have ever had with the saveDetectionMeasurements were when the output was over 2GB, and it doesn't sound like the issue here, so I am not sure what is happening. |
I wasn't sure whether select annotations/detections had to be called before the actual processing but if it can be avoived it is great as depending on how many objects you have it might be slow. yes it is generating one file per slide with the idea of deleting everything once the analysis is over for the slide (although this bit of code is commented now). outAnnoationsStatFname = "H://"+strfnameTrim+"_steatosis_annotations.txt" This is the line creating the variable holding the filename. It is not an issue of size (I thought about that too) because if you limit the analysis to the first 10 tiles for every slide you are dealing with files of <100K. Although the complete file it should be < 20MB. |
I’ve tried to replicate this, but couldn’t (albeit on my Mac). Which platform are you running on? There can indeed be trouble when trying to save very large detection measurement tables; a String is generated first then written to a file. The rationale was that this meant the same code could be used to generate data for copying to clipboard... but if the String ends up exceeding the maximum length permitted by Java, then it fails. Anyhow, I understand that's not the trouble here. Does it make any difference is you save the detections first, then the annotations? The option of last resort is probably to just write the export code operating on the detections directly. That would at least give maximum flexibility, and should be reasonably concise with Groovy. If you decide to go that way the following might help: def fileOutput = new File(buildFilePath(PROJECT_BASE_DIR, 'detections.txt'))
// Get the detections
def detections = getDetectionObjects()
// Get the names, in an ordered set
def names = new LinkedHashSet<>()
detections.each {names.addAll(it.getMeasurementList().getMeasurementNames())}
// Loop through objects & names
fileOutput.text = String.join('\t', names)
df = new java.text.DecimalFormat('#.###')
detections.each { detection ->
// Map measurements for the object to a suitably-formatted string
def values = names.collect({name -> df.format(detection.getMeasurementList().getMeasurementValue(name))})
fileOutput << String.join('\t', values) << System.lineSeparator()
}
print 'Done!' |
Ok, if the deletion part is commented out entirely, and the names are not overlapping, my only thoughts are whether the removal of the selectDetections code changes anything, as that slowdown has caused problems in another script that dealt with merging annotations (#129). The other would be to simply include the folder name and let the function generate the filename, to see if that part is working.
|
the removal of selectDetectionMeasurement() and guiscript=true didn't change anything. I will give a try to the suggestions above and try from another machine. The current platform is a Windows but at home I have a Mac. Will let you know. Thanks a mill for the quick feedback. |
Sorry my suggestions haven't been more useful! Also, I do get an empty text file with Name only when I export detection files and there are no detections present. Is there any chance you could perform a |
all suggestions above did not work. getDetections() doesn't seem to be defined or it is not visible within the java classes I import. I will try to setup IntelliJ. However getDetectionObjects() has a size 0 (both single and batch mode). Could this be the problem ? What I realised is that the same script but on objects that are created with Qupath and not with ImageJ works fine in both batch and single slide mode. Is there maybe a problem with the type of objects created by the ImageJ plugin that import the objects into qupath ? |
Right, getDetectionObjects was what I meant, thanks for figuring that out! And that sounds like we are a lot closer to figuring this out. |
If I read it correctly, a macro isn't involved but Python is. Could you give a bit more details on the arrangement and how you get the ROIs from the ROI Manager into QuPath? If you aren't doing it already, I think you might need to get into some of the helper classes like |
Oops, yes, he did say that in the first post. I think my wires got crossed while reading the forum post on automating the ImageJ macro runner across images. It is interesting that his import (and more importantly export) works for a single slide. I am still wondering if it not working in batch mode means that something isn't being given time to complete. @erexhepa When running it for a single slide, once all of the imported ROIs are in place, can you then use getDetectionObjects (on it's own as a separate script or menu command) to target anything? Does the Measure->Show detection measurements populate as soon as the script is complete? |
This is the code handling the interaction with ImageJ. Python code is called from ImageJ to handle some normalisation and convolutional tasks. I'm looking into the IJTools, RoiConverterIJ classes to see if I can find something useful. It is very strange because I can see the objects in QuPath and they are in the hierarchy. The gethierarchy method from QP class returns you the numbers of IJ objects plus the number of tiles but somehow during data extraction things get messed up. Meanwhile I find what is going on I will try to do the intensity/morphology measurements in ImageJ and save the results from IJ through calls to the RoiManager.
|
Aaaah.... that makes sense. The Send Overlay to QuPath command doesn't support batch mode, and requests the image currently open in the viewer. Code is at https://github.com/qupath/qupath/blob/v0.1.2/qupath-extension-ij/src/main/java/qupathj/QUPath_Send_Overlay_to_QuPath.java#L90 So the results are presumably being sent to the wrong image when called in batch mode. Because the |
👍 thanks. Should have put the code straight from the first post :). |
thanks again @petebankhead. That was the issue. I'm posting the code in case somebody else is interested.
|
I'm having a weird issue with the saveDetectionMeasurement().
Once all the tiles have been processed I call
When I select run script on one slide everything is fine.
When I try to run it in batch mode saveAnnotationMeasurements works and produces the same output as in single slide mode but saveDetectionMeasurement() produces only a file with the string "Name" in it.
Am I missing something on batch/single-slide mode ?
The text was updated successfully, but these errors were encountered: