@@ -473,13 +473,29 @@ def image_shape(self):
473
473
frame_indices = np .array (
474
474
[frame .FrameContentSequence [0 ].DimensionIndexValues
475
475
for frame in self .frames ])
476
- n_dim = frame_indices .shape [1 ] + 1
477
- # Check there is only one multiframe stack index
478
- if np .any (np .diff (frame_indices [:, 0 ])):
479
- raise WrapperError ("File contains more than one StackID. Cannot "
480
- "handle multi-stack files" )
476
+
477
+ # Check that there is only one multiframe stack index
478
+ stack_ids = set (frame .FrameContentSequence [0 ].get ('StackID' )
479
+ for frame in self .frames )
480
+ if len (stack_ids ) > 1 :
481
+ raise WrapperError ("File contains more than one StackID. "
482
+ "Cannot handle multi-stack files" )
483
+
484
+ # Determine if one of the Dimension indices refers to the stack id
485
+ dim_seq = [(dim .DimensionIndexPointer , dim .FunctionalGroupPointer )
486
+ 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 :
494
+ frame_indices = np .delete (frame_indices , stack_dim_idx , axis = 1 )
495
+
496
+ n_dim = frame_indices .shape [1 ] + 2
481
497
# Store frame indices
482
- self ._frame_indices = frame_indices [:, 1 :]
498
+ self ._frame_indices = frame_indices
483
499
if n_dim < 4 : # 3D volume
484
500
return rows , cols , n_frames
485
501
# More than 3 dimensions
0 commit comments