Skip to content
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

Setting the class of pathobjects changes the hierarchy #119

Open
ap-- opened this issue Sep 21, 2024 · 0 comments
Open

Setting the class of pathobjects changes the hierarchy #119

ap-- opened this issue Sep 21, 2024 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ap--
Copy link
Collaborator

ap-- commented Sep 21, 2024

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

paquo/paquo/pathobjects.py

Lines 221 to 229 in 18ae97a

def update_path_class(self: PathROIObjectType, pc: Optional[QuPathPathClass], probability: float = math.nan) -> None:
"""updating the class or probability has to be done via this method"""
if not (pc is None or isinstance(pc, QuPathPathClass)):
raise TypeError("requires QuPathPathClass")
else:
pc = pc if pc is None else pc.java_object
self.java_object.setPathClass(pc, probability)
if self._update_callback:
self._update_callback(self) # type: ignore[arg-type]

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

PathObjectProxy.add

paquo/paquo/hierarchy.py

Lines 132 to 146 in 18ae97a

def add(self, x: PathROIObjectType) -> None:
"""adds a new path object to the proxy"""
if self._mask:
raise OSError("cannot modify view")
if self._readonly:
raise OSError("project in readonly mode")
if not isinstance(x, self._paquo_cls):
raise TypeError(f"requires {self._paquo_cls.__name__} instance got {x.__class__.__name__}")
try:
if self._hierarchy.autoflush:
self._java_hierarchy.addObject(x.java_object, True)
else:
self._java_hierarchy.addObject(x.java_object, False)
finally:
self._list_invalidate_cache()

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.

@ap-- ap-- added bug Something isn't working help wanted Extra attention is needed labels Sep 21, 2024
@ap-- ap-- changed the title Setting the class of pathobjects looses the hierarchy Setting the class of pathobjects changes the hierarchy Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant