How to select Annotations by class

929 views
Skip to first unread message

David Haumann

unread,
Sep 11, 2017, 3:29:50 AM9/11/17
to QuPath users
I often face the situation, that I do simple tissue detection, SLIC, add features and run a classifier with 2 classes.

Then i convert the Tiles into ROI. The ROI carry the class name of the classified SLIC.

Now i have the Area AWT ROI from the simple tissue detection and a lot of small ROI with a class name inside.

The ongoing analysis shall be only in the inside ROI that carry a class name!

How can I automate the process?  For cell analysis, i need to select the ROI by class only - not the big tissue Annotation.

Is there a way of scripting, to select ROIs by its class name, if they are inside a tissue Annotation?

With "selectAnnotations();"  I allways get all annotations. If I now do any analysis command, the first thing that happens is, that all objects inside the tissue Annotation get deleted! So I allways have to do delete the tissue annotation by hand.

Does anybody have an idea?

Best
David

Pete

unread,
Sep 11, 2017, 3:36:57 AM9/11/17
to QuPath users
Does this script do what you want?

selectObjects {it.getPathClass() != null}

It's a bit of a weird syntax, but the part between {braces} is a closure (function), which will be applied to all the objects.  The 'it' is the current object that is currently being tested.

Extra criteria can be added.  For example, if you want to restrict the selection to only annotations, this should do it

selectObjects {it.isAnnotation() && it.getPathClass() != null}

micros...@gmail.com

unread,
Sep 11, 2017, 2:05:57 PM9/11/17
to QuPath users
And if you want only one of those annotations at a time, specifically, step 4 from the SLICs to areas tgread below contains...
selectObjects { p -> p.getPathClass() == getPathClass("Stroma") }

It would probably be cleaner to write this as it.etc, but it should work the same way for picking out annotations with a specific class (which usually will be the name).

David Haumann

unread,
Sep 12, 2017, 8:36:29 AM9/12/17
to QuPath users
Yes. Both helps. Thanks Pete. If i want to learn this syntax I need to learn Groovy?
That would really help me a lot and eliminate probably all manual steps.
Is there a possibility to delete all Annotations within the TissueAnnotation that are smaller than a chosen size/area?j For ex. delete all Class Follicle ROI smaller 5000µm²?

David Haumann

unread,
Sep 12, 2017, 8:37:26 AM9/12/17
to QuPath users
Also great help, micros! Thank you.

David Haumann

unread,
Sep 12, 2017, 9:56:57 AM9/12/17
to QuPath users
Another problem arose:
If i use the script, it works allone for itself.
but as soon as it becomes part of a script with more lines, an error occures:
ERROR: Error: startup failed:
Script13.groovy: 2: unexpected char: 0x0 @ line 2, column 42.
   ts {it.getPathClass() != null}
with hint that a sign is missing after "}"
How can i tell the script editor, that the next task shall be processed?  Usually every line in the script editor ends with "');"  But that does not help here.

For example cell analysis afterwards in the selected roi by class:
selectObjects {it.getPathClass() != null}
runPlugin('qupath.imagej.detect.nuclei.PositiveCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "backgroundRadius": 45.0,  "medianRadius": 2.0,  "sigma": 5.0,  "minArea": 10.0,  "maxArea": 1500.0,  "threshold": 0.05,  "maxBackground": 2.0,  "watershedPostProcess": true,  "cellExpansion": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true,  "thresholdCompartment": "Nucleus: DAB OD mean",  "thresholdPositive1": 0.2,  "thresholdPositive2": 0.4,  "thresholdPositive3": 0.6,  "singleThreshold": true}');


David Haumann

unread,
Sep 12, 2017, 11:56:08 AM9/12/17
to QuPath users
think i found the solution. I copied out the script from a word file. Word taggs any format thing that causes the script to fail. If i  copy it into text editor and then into script editor, it works.
Reply all
Reply to author
Forward
0 new messages