Skip to content

Commit d0aea2e

Browse files
committed
RF: Remove use of 'FunctionalGroupPointer' in determining 'StackID' axis
1 parent 39931c2 commit d0aea2e

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .dwiparams import B2q, nearest_pos_semi_def, q2bg
2222
from ..openers import ImageOpener
2323
from ..onetime import setattr_on_read as one_time
24-
24+
from ..pydicom_compat import pydicom
2525

2626
class WrapperError(Exception):
2727
pass
@@ -463,27 +463,30 @@ def __init__(self, dcm_data):
463463
def image_shape(self):
464464
"""The array shape as it will be returned by ``get_data()``
465465
466-
The shape is determined by the `Rows` DICOM attribute, `Columns`
466+
The shape is determined by the *Rows* DICOM attribute, *Columns*
467467
DICOM attribute, and the set of frame indices given by the
468-
`FrameContentSequence[0].DimensionIndexValues` DICOM attribute of each
469-
element in the `PerFrameFunctionalGroupsSequence`. The first two
468+
*FrameContentSequence[0].DimensionIndexValues* DICOM attribute of each
469+
element in the *PerFrameFunctionalGroupsSequence*. The first two
470470
axes of the returned shape correspond to the rows, and columns
471471
respectively. The remaining axes correspond to those of the frame
472472
indices with order preserved.
473473
474474
What each axis in the frame indices refers to is given by the
475-
corresponding entry in the `DimensionIndexSequence` DICOM attribute.
476-
WARNING, any axis refering to the `StackID` DICOM attribute will have
477-
been removed from the frame indices in determining the shape. This is
478-
because only a file containing a single stack is currently allowed by
475+
corresponding entry in the *DimensionIndexSequence* DICOM attribute.
476+
**WARNING**: Any axis refering to the *StackID* DICOM attribute will
477+
have been removed from the frame indices in determining the shape. This
478+
is because only a file containing a single stack is currently allowed by
479479
this wrapper.
480480
481481
References
482482
----------
483-
- C.7.6.17 Multi-frame Dimension Module of Supplement 49 of the DICOM
484-
standard.
485-
- C.7.6.16.2.2 Frame Content Macro of Supplement 49 of the DICOM
486-
standard.
483+
484+
* `C.7.6.16 Multi-Frame Functional Groups Module
485+
<http://dicom.nema.org/medical/dicom/current/output/pdf/part03.pdf#sect_C.7.6.16>_`
486+
487+
* `C.7.6.17 Multi-Frame Dimension Module
488+
<http://dicom.nema.org/medical/dicom/current/output/pdf/part03.pdf#sect_C.7.6.17>_`
489+
487490
"""
488491
rows, cols = self.get('Rows'), self.get('Columns')
489492
if None in (rows, cols):
@@ -500,17 +503,14 @@ def image_shape(self):
500503
if len(stack_ids) > 1:
501504
raise WrapperError("File contains more than one StackID. "
502505
"Cannot handle multi-stack files")
503-
# Determine if one of the Dimension indices refers to the stack id
504-
dim_seq = [(dim.DimensionIndexPointer, dim.FunctionalGroupPointer)
506+
# Determine if one of the dimension indices refers to the stack id
507+
dim_seq = [dim.DimensionIndexPointer
505508
for dim in self.get('DimensionIndexSequence')]
506-
# the pointer pair (StackID Dicom-tag, FrameContentSequence Dicom-tag)
507-
# that indicates that the corresponding axis in the DimensionIndexValues
508-
# attribute refers to the StackID
509-
stack_id_dim_pointer = ((0x20, 0x9056), (0x20, 0x9111))
510-
# remove superfluous stack id index if present
511-
if stack_id_dim_pointer in dim_seq:
512-
stack_dim_idx = dim_seq.index(stack_id_dim_pointer)
513-
frame_indices = np.delete(frame_indices, stack_dim_idx, axis=1)
509+
stackid_tag = pydicom.datadict.tag_for_name('StackID')
510+
# remove the stack id axis if present
511+
if stackid_tag in dim_seq:
512+
stackid_dim_idx = dim_seq.index(stackid_tag)
513+
frame_indices = np.delete(frame_indices, stackid_dim_idx, axis=1)
514514
# account for the 2 additional dimensions (row and column) not included
515515
# in the indices
516516
n_dim = frame_indices.shape[1] + 2

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,10 @@ def fake_shape_dependents(div_seq, sid_seq=None, sid_dim=None):
394394
the index of the column in 'div_seq' to use as 'sid_seq'
395395
"""
396396
class DimIdxSeqElem(object):
397-
def __init__(self, dip=(0, 0), fgp=(0, 0)):
397+
def __init__(self, dip=(0, 0), fgp=None):
398398
self.DimensionIndexPointer = dip
399-
self.FunctionalGroupPointer = fgp
399+
if fgp is not None:
400+
self.FunctionalGroupPointer = fgp
400401
class FrmContSeqElem(object):
401402
def __init__(self, div, sid):
402403
self.DimensionIndexValues = div
@@ -415,7 +416,9 @@ def __init__(self, div, sid):
415416
dim_idx_seq = [DimIdxSeqElem()] * num_of_frames
416417
# add an entry for StackID into the DimensionIndexSequence
417418
if sid_dim is not None:
418-
dim_idx_seq[sid_dim] = DimIdxSeqElem((0x20, 0x9056), (0x20, 0x9111))
419+
sid_tag = pydicom.datadict.tag_for_name('StackID')
420+
fcs_tag = pydicom.datadict.tag_for_name('FrameContentSequence')
421+
dim_idx_seq[sid_dim] = DimIdxSeqElem(sid_tag, fcs_tag)
419422
# create the PerFrameFunctionalGroupsSequence
420423
frames = [PerFrmFuncGrpSeqElem(div, sid)
421424
for div, sid in zip(div_seq, sid_seq)]

0 commit comments

Comments
 (0)