Delete annotation outside another

Hi all,

I want to create a grid inside an annotation to study heterogeneity.
To do so, I get the annotation bounds and add rectangle annotations. But, sometimes (at the edges), the rectangle annotation is not completely inside the parent one. So I would like to remove it. But I don’t know how to do it.
The thing I can do is to test whether the candidate annotation is inside or not (with getLevel()), but after, I don’t know how to select it.

Thanks for your help

(and by the way, is there a place were all methods are listed, something like the built-in macro function page for imageJ)


Many functions are listed in the workflow tab, if you use the Create script button, but not all.

Is there any reason not to use tiling to create annotations? That has an option to automatically trim all tiles to the parent annotation.
Which can then be scripted.

Alternately, you can use the level, but you will need to Intersect the annotations. There are a few other posts on the forums about finding the overlap or intersection between objects, I would start there.

Thanks for your response.
Tiling seems to be great. But I can’t find it in the menus. Where is it ?

For the overlaping, I used the addObject(toto) were toto = new PathAnnotationObject(roi). After ading, the ouside annotations has a level ==1. But after that, i don’t manage to select the annotation to delete it.

Sorry, rushed.

Also, command+L or CTRL+L to get a list you can search for commands rather than looking through the menus.

Thanks for the less command :slight_smile:

Now, I just have to understand why
runPlugin(‘qupath.opencv.CellCountsCV’, ‘…’);
runPlugin(‘qupath.lib.algorithms.TilerPlugin’, ‘{“tileSizeMicrons”: 100.0, “trimToROI”: true, “makeAnnotations”: true, “removeParentAnnotation”: false}’);
erases all detections and then creates the tiles, and why in the reverse order it erases all the tiles and creates the detection while it seems to work by hand (except that only half of the tiles where processed :slight_smile:

Generally you can only run one detection command at a time within an annotation. So if you want tiles with cells in them, you need to split the annotation into annotation tiles first, then selectAnnotations(), then run your cell detection.

For people interested ; finally, I created the grid, removed the top level annotations and ran the cell detection in the remaining annotations :

runPlugin('qupath.lib.algorithms.TilerPlugin', '{"tileSizeMicrons": 100.0,  "trimToROI": true,  "makeAnnotations": true,  "removeParentAnnotation": false}');

targets = getObjects{return it.getLevel()==1 && it.isAnnotation()}

runPlugin('qupath.opencv.CellCountsCV', '{"stainChannel": "Hematoxylin + DAB",  "gaussianSigmaMicrons": 3.0,  "backgroundRadiusMicrons": 5.0,  "doDoG": true,  "threshold": 0.1,  "thresholdDAB": 0.05,  "detectionDiameter": 15.0}');


1 Like