-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add coordinate for Measurement in SR #307
Merged
CPBridge
merged 9 commits into
ImagingDataCommons:v0.24.0dev
from
Fedalto:add-coordinates-measurements-sr
Oct 19, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
65eaf3b
Add coordinate for Measurement in SR
Fedalto 73452a1
fix import style
Fedalto ab6bb55
Add `Measurement.referenced_coordinates` parameter
Fedalto 867cee4
Add `purpose` parameter to CoordinatesForMeasurement.__init__
Fedalto 81dd8fb
Change `SourceImageForRegion` concept name to `codes.SCT.Source`
Fedalto 9f6d673
Only allow coordinates in measurements in `MeasurementsAndQualitative…
Fedalto f97fe3a
Add `CoordinatesForMeasurement3D`
Fedalto 1012fad
Change casting to use `cls`
CPBridge 3aca8ff
Favour CoordinatesForMeasurement3D over Scoord3DContentItem
CPBridge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,16 @@ | |
from pydicom.valuerep import DA, DS, DT, TM, PersonName | ||
from pydicom.uid import SegmentationStorage | ||
|
||
from highdicom.sr import CodedConcept | ||
from highdicom.sr import ( | ||
AlgorithmIdentification, | ||
CodeContentItem, | ||
CodedConcept, | ||
CompositeContentItem, | ||
Comprehensive3DSR, | ||
ComprehensiveSR, | ||
ContainerContentItem, | ||
ContentSequence, | ||
CoordinatesForMeasurement3D, | ||
DateContentItem, | ||
DateTimeContentItem, | ||
DeviceObserverIdentifyingAttributes, | ||
|
@@ -75,6 +76,7 @@ | |
VolumetricROIMeasurementsAndQualitativeEvaluations, | ||
srread, | ||
) | ||
from highdicom.sr.content import CoordinatesForMeasurement | ||
from highdicom.sr.utils import find_content_items | ||
from highdicom import UID | ||
|
||
|
@@ -2141,6 +2143,31 @@ def test_from_invalid_source_image_seg(self): | |
) | ||
|
||
|
||
class TestCoordinatesForMeasurement(unittest.TestCase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.source_image = SourceImageForRegion( | ||
referenced_sop_class_uid='1.2.840.10008.5.1.4.1.1.2', | ||
referenced_sop_instance_uid='1.2.3.4.5.6.7.8.9.10' | ||
) | ||
|
||
def test_construction(self): | ||
item = CoordinatesForMeasurement( | ||
graphic_type=GraphicTypeValues.MULTIPOINT, | ||
graphic_data=np.array([[10, 20], [20, 30]]), | ||
source_image=self.source_image | ||
) | ||
|
||
assert item.graphic_type == GraphicTypeValues.MULTIPOINT | ||
assert item.GraphicData == [10, 20, 20, 30] | ||
assert item.relationship_type == RelationshipTypeValues.INFERRED_FROM | ||
|
||
assert len(item.ContentSequence) == 1 | ||
assert item.ContentSequence[0] == self.source_image | ||
assert item.ContentSequence[0].relationship_type == RelationshipTypeValues.SELECTED_FROM | ||
|
||
|
||
class TestReferencedSegment(unittest.TestCase): | ||
|
||
def setUp(self): | ||
|
@@ -2807,6 +2834,30 @@ def test_construction_with_optional_parameters(self): | |
assert isinstance(retrieved, SourceImageForMeasurement) | ||
assert retrieved == original | ||
|
||
def test_referenced_coordinates(self): | ||
scoord = CoordinatesForMeasurement( | ||
graphic_type="POINT", | ||
graphic_data=np.array([[50.0, 50.0]]), | ||
source_image=self._image | ||
) | ||
scoord_3d = CoordinatesForMeasurement3D( | ||
graphic_type="POINT", | ||
graphic_data=np.array([[50.0, 50.0, 30.0]]), | ||
frame_of_reference_uid="1.2.3.4.5.6.7.8.9" | ||
) | ||
measurement = Measurement( | ||
name=self._name, | ||
value=self._value, | ||
unit=self._unit, | ||
referenced_coordinates=[scoord, scoord_3d], | ||
) | ||
|
||
assert len(measurement.referenced_coordinates) == 2 | ||
assert scoord in measurement.referenced_coordinates | ||
assert scoord_3d in measurement.referenced_coordinates | ||
CPBridge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert isinstance(measurement.referenced_coordinates[0], CoordinatesForMeasurement) | ||
assert isinstance(measurement.referenced_coordinates[1], CoordinatesForMeasurement3D) | ||
|
||
|
||
class TestQualitativeEvaluation(unittest.TestCase): | ||
|
||
|
@@ -3068,6 +3119,24 @@ def test_constructed_with_multiple_references(self): | |
referenced_segment=self._segment | ||
) | ||
|
||
def test_constructed_with_measurements_coordinates(self): | ||
measurement = Measurement( | ||
name=codes.SCT.Diameter, | ||
value=5, | ||
unit=codes.UCUM.Millimeter, | ||
referenced_coordinates=[CoordinatesForMeasurement( | ||
graphic_type=GraphicTypeValues.POLYLINE, | ||
graphic_data=np.array([[1, 1], [2, 2]]), | ||
source_image=self._image_for_region | ||
)] | ||
) | ||
with pytest.raises(ValueError) as exc: | ||
PlanarROIMeasurementsAndQualitativeEvaluations( | ||
tracking_identifier=self._tracking_identifier, | ||
referenced_region=self._region, | ||
measurements=[measurement], | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test somewhere that the new |
||
|
||
|
||
class TestVolumetricROIMeasurementsAndQualitativeEvaluations(unittest.TestCase): | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with ImageRegion, but I reused
SourceImageForRegion
here as it needs to be an image withSELECTED FROM
relationship. Not sure if there's a better option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting question.
SourceImageForRegion
pretty much matches the requirements of the ImageContentItem that would be used here, but the concept name used may pose a problem.The concept name is blank in table TID 320, but the highdicom content item class does not allow "unnamed" content items (this issue arises in a few places and we made this design decision fairly early on). SourceImageForRegion uses the concept name (DCM, 111040, Original Source), whereas it states at the bottom of TID 320 that
so we should follow that here, which implies that SourceImageForRegion as it is currently written would not be appropriate.
However, looking at the other places that
SourceImageForRegion
is used (basically row six of TID 1410 and TID 1411), I notice that the same suggestion to use SCT 260753009 is given there. I am not sure whySourceImageForRegion
uses DCM 111040, it appears that this goes all the way back to the beginning of the library. Perhaps @hackermd can shed some lightGiven this, I favour changing
SourceImageForRegion
to use SCT 260753009 and then usingSourceImageForRegion
as you propose for TID 320.