21
21
from .dwiparams import B2q , nearest_pos_semi_def , q2bg
22
22
from ..openers import ImageOpener
23
23
from ..onetime import setattr_on_read as one_time
24
-
24
+ from .. pydicom_compat import pydicom
25
25
26
26
class WrapperError (Exception ):
27
27
pass
@@ -463,27 +463,30 @@ def __init__(self, dcm_data):
463
463
def image_shape (self ):
464
464
"""The array shape as it will be returned by ``get_data()``
465
465
466
- The shape is determined by the ` Rows` DICOM attribute, ` Columns`
466
+ The shape is determined by the * Rows* DICOM attribute, * Columns*
467
467
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
470
470
axes of the returned shape correspond to the rows, and columns
471
471
respectively. The remaining axes correspond to those of the frame
472
472
indices with order preserved.
473
473
474
474
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
479
479
this wrapper.
480
480
481
481
References
482
482
----------
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
+
487
490
"""
488
491
rows , cols = self .get ('Rows' ), self .get ('Columns' )
489
492
if None in (rows , cols ):
@@ -500,17 +503,14 @@ def image_shape(self):
500
503
if len (stack_ids ) > 1 :
501
504
raise WrapperError ("File contains more than one StackID. "
502
505
"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
505
508
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 )
514
514
# account for the 2 additional dimensions (row and column) not included
515
515
# in the indices
516
516
n_dim = frame_indices .shape [1 ] + 2
0 commit comments