Bayer-Group / paquo

PAthological QUpath Obsession - QuPath and Python conversations
GNU General Public License v3.0
104 stars 16 forks source link

Setting the class of pathobjects changes the hierarchy #119

Open ap-- opened 1 month ago

ap-- commented 1 month ago

As reported here:

https://forum.image.sc/t/paquo-detection-path-class-updates-causing-changes-in-hierarchy/101806/5

Solution is likely to be:

from @petebankhead Yes, the object hierarchy doesn’t usually know when the properties of an object change – which is a good thing, because hierarchy updates are expensive.

You do generally need to remove/add an object if its ROI changes, but not if its classification changes.

The relevant code paths are:

update_path_class

https://github.com/Bayer-Group/paquo/blob/18ae97a3dd73267d0fada0f15e2515affb1201d5/paquo/pathobjects.py#L221-L229

on an existing hierarchy this will call the _update_callback. This is set here

PathObjectProxy.add

https://github.com/Bayer-Group/paquo/blob/18ae97a3dd73267d0fada0f15e2515affb1201d5/paquo/hierarchy.py#L132-L146

get's called then and is probably the cause for loosing the hierarchy. we could just disable it for modifications that are not related to the ROI of the pathobject.

Easiest way would be to add a update_hierarchy kwarg to the PathObjectProxy.add which defaults to True and pass update_hierarchy=False to the callback when updating the class.

We should first add a test that reproduces the current issue though.