Skip to content

Commit d5d2a0a

Browse files
authored
Merge pull request #320 from ImagingDataCommons/feature/get_frames_method
Add get_frames and get_stored_frames methods
2 parents 1654cc1 + 2bdeac5 commit d5d2a0a

5 files changed

Lines changed: 372 additions & 19 deletions

File tree

docs/image.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ processing unnecessary frames. If you know that you are likely to access frames
124124
multiple times, you can force caching of the stored values by accessing the
125125
``.pixel_array`` property (inherited from ``pydicom.Dataset``).
126126

127+
Additionally, there are two methods for accessing multiple frames at a time:
128+
129+
* :meth:`highdicom.Image.get_stored_frames()`: Returns a stack of multiple
130+
stored frames. The first parameter is a list (or other iterable) of frame
131+
numbers. If omitted, all frames are returned in the order they are stored in
132+
the image.
133+
* :meth:`highdicom.Image.get_frames()`: Returns a stack of multiple
134+
frames with pixel transforms applied. The first parameter is a list (or other
135+
iterable) of frame numbers. If omitted, all frames are returned in the order
136+
they are stored in the image.
137+
127138
Accessing Total Pixel Matrices
128139
------------------------------
129140

docs/pixel_transforms.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The :class:`highdicom.Image` class has several methods that return frames or
5050
arrangements of frames from a DICOM image:
5151

5252
* :meth:`highdicom.Image.get_frame()`
53+
* :meth:`highdicom.Image.get_frames()`
5354
* :meth:`highdicom.Image.get_volume()`
5455
* :meth:`highdicom.Image.get_total_pixel_matrix()`
5556

docs/seg.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ segmentation type.
345345

346346
.. code-block:: python
347347
348-
import numpy as np
349-
350348
from pydicom.sr.codedict import codes
351349
from pydicom.data import get_testdata_file
352350
@@ -355,13 +353,8 @@ segmentation type.
355353
# Load an enhanced (multiframe) CT image
356354
source_image = hd.imread(get_testdata_file('eCT_Supplemental.dcm'))
357355
358-
# Stack all the frames of the image
359-
image_array = np.stack(
360-
[
361-
source_image.get_frame(i + 1)
362-
for i in range(source_image.number_of_frames)
363-
]
364-
)
356+
# Get a stack of all the frames of the image
357+
image_array = source_image.get_frames()
365358
366359
# Create a segmentation by thresholding the CT image at 0 HU
367360
mask = image_array > 0

0 commit comments

Comments
 (0)