NKI-AI / dlup

Dlup are the Deep Learning Utilities for Pathology developed at the Netherlands Cancer Institute
Apache License 2.0
25 stars 7 forks source link

Bounding box property WSIAnnotations class errors when loading multipoint. #150

Closed Dafidofff closed 1 year ago

Dafidofff commented 1 year ago

Describe the bug When calling the property bounding_box of the WSIAnnotation class return an the following attribute error AttributeError: 'Point' object has no attribute 'exterior'

To Reproduce

from pathlib import Path

from dlup import SlideImage
from dlup.annotations import WsiAnnotations

slide_path = Path("/data/datasets/NKI/slides/1285/195551/T17-06278 A1 PD-L1 (22C3).svs")
anno_path = Path("/data/datasets/NKI/data/annotations/studies/slidescore_1285/v20230210-0/annotations/wsong@ellogon.ai/195551/Lymphocytes.json")  # --> multipoint annotation
dlup_slide = SlideImage.from_file_path(slide_path)
dlup_anno = WsiAnnotations.from_geojson(anno_path)

# wsi = dlup_slide.read_region(location=(0,0), size=dlup_slide.size, scaling=1.0)
anno_in_region = dlup_anno.read_region(coordinates=(0,0), region_size=dlup_slide.size, scaling=0.01)
print(anno_in_region)

bounds = dlup_anno.bounding_box

Gives the following error:

Traceback (most recent call last):
  File "/homes/dwessels/LightningGon/test_multipoint.py", line 41, in <module>
    bounds = dlup_anno.bounding_box
  File "/homes/dwessels/.cache/pypoetry/virtualenvs/lgon-WMDuiRwL-py3.10/lib/python3.10/site-packages/dlup/annotations.py", line 321, in bounding_box
    curr_bboxes = self[label].bounding_boxes
  File "/homes/dwessels/.cache/pypoetry/virtualenvs/lgon-WMDuiRwL-py3.10/lib/python3.10/site-packages/dlup/annotations.py", line 227, in bounding_boxes
    data = [np.asarray(annotation.envelope.exterior.coords) for annotation in self.as_list()]
  File "/homes/dwessels/.cache/pypoetry/virtualenvs/lgon-WMDuiRwL-py3.10/lib/python3.10/site-packages/dlup/annotations.py", line 227, in <listcomp>
    data = [np.asarray(annotation.envelope.exterior.coords) for annotation in self.as_list()]
AttributeError: 'Point' object has no attribute 'exterior'

Expected behavior Give back then bounds of the point annotations, something like the following:

points = dlup_anno._annotations["Lymphocytes"].as_list()
bounds = [point.bounds[:2] for point in points]

Environment dlup version: 0.3.23 How installed: via Git on branch #148 Python version: 3.10.8 Operating System: Linux

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

jonasteuwen commented 1 year ago

This will be fixed in the upcoming release