QuPath Subtract Annotations confused about Hierarchy

I’ve noticed that sometimes (~50% in this one application), when I use the Subtract Annotations command in QuPath it confuses which is the parent object and which is the child, leading to it deleting everything.

My workflow:
Simple Tissue Detection (there’s only 1 piece of tissue, so it’s only 1 simple region)
Expand Annotations by -1000 to create an inner circle
Select Both
Subtract Annotations

If I select the annotations by clicking on the image or on them on the Annotations tab, it works half the time. In the annotation list, the order that it puts the objects seems to matter, and seems to change randomly. If I select the annotations by clicking on them in the Hierarchy tab, it works (almost?) 100% of the time.

I generally do this by scripting the subtraction; have you taken a look at the reduce annotations thread? Pete’s script and my variant of it have a bunch of subtraction examples. I used to differentiate between my two target annotations by classifying the expansion differently as well.

Also guessing this might be 0.2.0? If so the timing is killing me :slight_smile:

It is 0.2.0 m2!

I agree scripting is more straightforward, but I’m working with a user who wants to do learn how to do it themselves and is uncomfortable scripting. The fact that the same sequence of actions gives different results sometimes does imply there’s a bug, even if a script can avoid it.

Thanks for pointing me to the reduce annotations thread. I hadn’t seen it, and it’s got a bunch of interesting stuff that I’m sure I will need soon. Including for this project, if they’ll let me take over and automate everything :slight_smile:

Mm, and note that that stuff was all written for 0.1.3 and below. The Java Topology Suite stuff apparently changes much of what is used in those scripts. Bewaaaaaaare.

Final comment for tonight! Probably.
Always make sure the interior annotation is selected first if you are using the right click context menu subtraction. Think “Subtract First from the Second” where it would be written as Second-First = result. The order of selection is important.

Hopefully this commit will help in the next milestone.

The problem is that there can be multiple selected objects, but one ‘primary’ selected object. For simple shapes (e.g. rectangles) this is the one with the square handles allowing it to be resized, but for complex shapes without handles this is less clear.

Selection changes in the annotation/hierarchy pane weren’t setting the ‘primary’ selected object correctly, which is important for subtraction to occur properly.

I never remembered what order it should be for subtraction, but the rule seems to be that other annotations* are selected from the ‘primary’.

*-It looks like only one other annotation is subtracted, not all of them. I think this should be changed so that everything is subtracted from the primary.

Also, I think that a ‘difference’ command would be worthwhile, since this would reduce the importance of the order… although could still become complex with multiple annotations overlay the same region.

1 Like