8000 Improve logic to match segmentation frames to source images by CPBridge · Pull Request #361 · ImagingDataCommons/highdicom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve logic to match segmentation frames to source images #361

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

Open
wants to merge 13 commits into
base: v0.26.0dev
Choose a base branch
from
13 changes: 8 additions & 5 deletions docs/volume.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ well as specifying the coordinate system being used.
assert np.array_equal(vol.affine, affine)

# The datatype of the array, its shape, and the spatial shape (not
# including any channels), may be accessed via properties
# including any channels, see below), may be accessed via
# properties
print(vol.dtype)
# uint8

Expand Down Expand Up @@ -215,7 +216,7 @@ volume.
get_testdata_file('dicomdirtests/77654033/CT2/17166'),
]
ct_series = [pydicom.dcmread(f) for f in ct_files]

vol = get_volume_from_series(ct_series)

Array Manipulation
Expand Down Expand Up @@ -307,8 +308,9 @@ of the array:
spatial shape.
* :meth:`highdicom.Volume.flip_spatial()`, flips along certain axes.
* :meth:`highdicom.Volume.match_geometry()`, given a second volume (or volume
geometry) manipulate the volume by permutations, flips, crops and/or pads to
match the geometry of the first volume to that of the second volume.
geometry) manipulate the volume by axis permutations, flips, crops and/or
pads (but no resampling) to match the geometry of the first volume to that of
the second volume.
* :meth:`highdicom.Volume.pad()`, pads the array along spatial dimensions.
* :meth:`highdicom.Volume.pad_to_spatial_shape()`, pad to a given spatial
shape.
Expand Down Expand Up @@ -644,7 +646,8 @@ spatial metadata in the output object is correct.
seg_dataset.save_as('segmentation.dcm')

# Alternatively, it may be desirable to match the geometry of the output
# segmentation image to that of the input image
# segmentation image to that of the input image. This will "undo" the
# cropping and axis permutation operations done to the image volume above.
seg_volume_matched = seg_volume.match_geometry(original_volume)

# Use the segmentation volume as input to create a DICOM Segmentation
Expand Down
11 changes: 11 additions & 0 deletions src/highdicom/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,17 @@ def __init__(
)
self.append(item)

@property
def cosines(self) -> tuple[float, float, float, float, float, float]:
"""tuple[float, float, float, float, float, float]:

Direction cosines.

"""
if hasattr(self[0], 'ImageOrientationPatient'):
return tuple(self[0].ImageOrientationPatient)
return tuple(self[0].ImageOrientationSlide)

def __eq__(self, other: object) -> bool:
"""Determines whether two image planes have the same orientation.

Expand Down
Loading
0