Skip to content

Commit 62ed070

Browse files
committed
BF: Correct StackID DICOM tags
1 parent cf71eac commit 62ed070

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def image_shape(self):
475475
for frame in self.frames])
476476

477477
# Check that there is only one multiframe stack index
478-
stack_ids = set(frame.FrameContentSequence[0].get('StackID')
478+
stack_ids = set(frame.FrameContentSequence[0].StackID
479479
for frame in self.frames)
480480
if len(stack_ids) > 1:
481481
raise WrapperError("File contains more than one StackID. "
@@ -484,15 +484,16 @@ def image_shape(self):
484484
# Determine if one of the Dimension indices refers to the stack id
485485
dim_seq = [(dim.DimensionIndexPointer, dim.FunctionalGroupPointer)
486486
for dim in self.get('DimensionIndexSequence')]
487-
try:
488-
stack_dim_idx = dim_seq.index(((0x14, 0x2369), (0x14, 0x2397)))
489-
except ValueError:
490-
stack_dim_idx = None
491-
492-
# remove superfluous stack id index
493-
if stack_dim_idx is not None:
487+
# the pointer pair (StackID tag, FrameContentSequence tag) that
488+
# indicates that the dimension refers to the StackID
489+
stack_id_dim_pointer = ((0x20, 0x9056), (0x20, 0x9111))
490+
# remove superfluous stack id index if present
491+
if stack_id_dim_pointer in dim_seq:
492+
stack_dim_idx = dim_seq.index(stack_id_dim_pointer)
494493
frame_indices = np.delete(frame_indices, stack_dim_idx, axis=1)
495494

495+
# account for the 2 additional dimensions (row and column) not included
496+
# in the indices
496497
n_dim = frame_indices.shape[1] + 2
497498
# Store frame indices
498499
self._frame_indices = frame_indices

0 commit comments

Comments
 (0)