Skip to content

Commit 8fcc157

Browse files
authored
Fix decoding of graphic data in annotations group (#192)
1 parent 4c3a6a6 commit 8fcc157

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/highdicom/ann/content.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def get_graphic_data(
502502
Parameters
503503
----------
504504
coordinate_type: Union[str, highdicom.ann.AnnotationCoordinateTypeValues]
505-
Coordinate type of annotation
505+
Coordinate type of annotations
506506
507507
Returns
508508
-------
@@ -512,7 +512,7 @@ def get_graphic_data(
512512
513513
""" # noqa: E501
514514
coordinate_type = AnnotationCoordinateTypeValues(coordinate_type)
515-
if self._graphic_data:
515+
if len(self._graphic_data) > 0:
516516
if coordinate_type not in self._graphic_data:
517517
raise ValueError(
518518
'Graphic data is not available for Annotation Coordinate '
@@ -595,7 +595,7 @@ def get_graphic_data(
595595
indices_or_sections=split_param
596596
)
597597

598-
self._graphic_data[coordinate_type] = graphic_data
598+
self._graphic_data = {coordinate_type: graphic_data}
599599

600600
return self._graphic_data[coordinate_type]
601601

@@ -758,7 +758,7 @@ def from_dataset(cls, dataset: Dataset) -> 'AnnotationGroup':
758758
highdicom.ann.AnnotationGroup
759759
Item of the Annotation Group Sequence
760760
761-
"""
761+
""" # noqa: E501
762762
if not isinstance(dataset, Dataset):
763763
raise TypeError(
764764
'Dataset must be of type pydicom.dataset.Dataset.'
@@ -770,7 +770,7 @@ def from_dataset(cls, dataset: Dataset) -> 'AnnotationGroup':
770770
)
771771
group = deepcopy(dataset)
772772
group.__class__ = cls
773-
group._graphic_data = {}
773+
group._graphic_data = {} # will be handled by get_graphic_data()
774774

775775
group.AnnotationPropertyCategoryCodeSequence = [
776776
CodedConcept.from_dataset(

src/highdicom/ann/sop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ def from_dataset(
405405
)
406406
if dataset.SOPClassUID != '1.2.840.10008.5.1.4.1.1.91.1':
407407
raise ValueError(
408-
'Dataset is not a Microscopy Bulk Simple Annotation.'
408+
'Dataset is not a Microscopy Bulk Simple Annotations '
409+
'instance.'
409410
)
410411
_check_little_endian(dataset)
411412
ann = deepcopy(dataset)

tests/test_ann.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from highdicom.ann.content import Measurements, AnnotationGroup
1313
from highdicom.ann.enum import (
14+
AnnotationCoordinateTypeValues,
1415
AnnotationGroupGenerationTypeValues,
1516
GraphicTypeValues,
1617
)
@@ -231,6 +232,10 @@ def test_construction(self):
231232
assert values.shape == (2, 0)
232233

233234
def test_alternative_construction_from_dataset(self):
235+
coordinates_data = np.array(
236+
[1.0, 1.0, 2.0, 2.0, 3.0, 3.0],
237+
dtype=np.double
238+
)
234239
dataset = Dataset()
235240
dataset.AnnotationGroupNumber = 1
236241
dataset.AnnotationGroupUID = str(UID())
@@ -249,19 +254,34 @@ def test_alternative_construction_from_dataset(self):
249254
dataset.AnnotationPropertyTypeCodeSequence = [annotated_type]
250255
dataset.NumberOfAnnotations = 3
251256
dataset.GraphicType = 'POINT'
252-
dataset.DoublePointCoordinatesData = [1.0, 1.0, 2.0, 2.0, 3.0, 3.0]
257+
dataset.DoublePointCoordinatesData = coordinates_data.tobytes()
253258
dataset.AnnotationAppliesToAllZPlanes = 'NO'
254259
dataset.AnnotationAppliesToAllOpticalPaths = 'YES'
255260

256261
group = AnnotationGroup.from_dataset(dataset)
257262
assert isinstance(group, AnnotationGroup)
258263
assert isinstance(group.graphic_type, GraphicTypeValues)
259-
assert isinstance(group.algorithm_type,
260-
AnnotationGroupGenerationTypeValues)
264+
assert isinstance(
265+
group.algorithm_type,
266+
AnnotationGroupGenerationTypeValues
267+
)
261268
assert group.algorithm_identification is None
262269
assert isinstance(group.annotated_property_category, CodedConcept)
263270
assert isinstance(group.annotated_property_type, CodedConcept)
264271

272+
graphic_data = group.get_graphic_data(
273+
coordinate_type=AnnotationCoordinateTypeValues.SCOORD
274+
)
275+
assert isinstance(graphic_data, list)
276+
assert len(graphic_data) == 3
277+
assert graphic_data[0].dtype == np.double
278+
assert graphic_data[0].shape[1] == 2
279+
assert graphic_data[0].shape[0] == 1
280+
assert np.array_equal(
281+
graphic_data[0],
282+
np.array([[1.0, 1.0]], dtype=np.double)
283+
)
284+
265285
names, values, units = group.get_measurements()
266286
assert names == []
267287
assert units == []

0 commit comments

Comments
 (0)