@@ -461,7 +461,30 @@ def __init__(self, dcm_data):
461
461
462
462
@one_time
463
463
def image_shape (self ):
464
- """The array shape as it will be returned by ``get_data()``"""
464
+ """The array shape as it will be returned by ``get_data()``
465
+
466
+ The shape is determined by the `Rows` DICOM attribute, `Columns`
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
470
+ axes of the returned shape correspond to the rows, and columns
471
+ respectively. The remaining axes correspond to those of the frame
472
+ indices with order preserved.
473
+
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
479
+ this wrapper.
480
+
481
+ References
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.
487
+ """
465
488
rows , cols = self .get ('Rows' ), self .get ('Columns' )
466
489
if None in (rows , cols ):
467
490
raise WrapperError ("Rows and/or Columns are empty." )
@@ -471,25 +494,23 @@ def image_shape(self):
471
494
frame_indices = np .array (
472
495
[frame .FrameContentSequence [0 ].DimensionIndexValues
473
496
for frame in self .frames ])
474
-
475
497
# Check that there is only one multiframe stack index
476
498
stack_ids = set (frame .FrameContentSequence [0 ].StackID
477
499
for frame in self .frames )
478
500
if len (stack_ids ) > 1 :
479
501
raise WrapperError ("File contains more than one StackID. "
480
502
"Cannot handle multi-stack files" )
481
-
482
503
# Determine if one of the Dimension indices refers to the stack id
483
504
dim_seq = [(dim .DimensionIndexPointer , dim .FunctionalGroupPointer )
484
505
for dim in self .get ('DimensionIndexSequence' )]
485
- # the pointer pair (StackID tag, FrameContentSequence tag) that
486
- # indicates that the dimension refers to the StackID
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
487
509
stack_id_dim_pointer = ((0x20 , 0x9056 ), (0x20 , 0x9111 ))
488
510
# remove superfluous stack id index if present
489
511
if stack_id_dim_pointer in dim_seq :
490
512
stack_dim_idx = dim_seq .index (stack_id_dim_pointer )
491
513
frame_indices = np .delete (frame_indices , stack_dim_idx , axis = 1 )
492
-
493
514
# account for the 2 additional dimensions (row and column) not included
494
515
# in the indices
495
516
n_dim = frame_indices .shape [1 ] + 2
0 commit comments