@@ -461,23 +461,10 @@ def __init__(self, dcm_data):
461
461
Wrapper .__init__ (self , dcm_data )
462
462
self .dcm_data = dcm_data
463
463
self .frames = dcm_data .get ('PerFrameFunctionalGroupsSequence' )
464
- self ._nframes = self .get ('NumberOfFrames' )
465
464
try :
466
465
self .frames [0 ]
467
466
except TypeError :
468
467
raise WrapperError ("PerFrameFunctionalGroupsSequence is empty." )
469
- try :
470
- # DWI image where derived isotropic, ADC or trace volume
471
- # was appended to the series
472
- if self .frames [0 ].get ([0x18 , 0x9117 ], None ):
473
- self .frames = Sequence (
474
- frame for frame in self .frames if
475
- frame .get ([0x18 , 0x9117 ])[0 ].get ([0x18 , 0x9075 ]).value
476
- != 'ISOTROPIC'
477
- )
478
- self ._nframes = len (self .frames )
479
- except AttributeError :
480
- pass
481
468
try :
482
469
self .shared = dcm_data .get ('SharedFunctionalGroupsSequence' )[0 ]
483
470
except TypeError :
@@ -515,8 +502,23 @@ def image_shape(self):
515
502
rows , cols = self .get ('Rows' ), self .get ('Columns' )
516
503
if None in (rows , cols ):
517
504
raise WrapperError ("Rows and/or Columns are empty." )
505
+
518
506
# Check number of frames
519
- assert len (self .frames ) == self ._nframes
507
+ first_frame = self .frames [0 ]
508
+ n_frames = self .get ('NumberOfFrames' )
509
+ # some Philips may have derived images appended
510
+ has_derived = False
511
+ if hasattr (first_frame , 'get' ) and first_frame .get ([0x18 , 0x9117 ]):
512
+ # DWI image may include derived isotropic, ADC or trace volume
513
+ # check and remove
514
+ self .frames = Sequence (
515
+ frame for frame in self .frames if
516
+ frame .get ([0x18 , 0x9117 ])[0 ].get ([0x18 , 0x9075 ]).value
517
+ != 'ISOTROPIC'
518
+ )
519
+ n_frames = len (self .frames )
520
+ has_derived = True
521
+ assert len (self .frames ) == n_frames
520
522
frame_indices = np .array (
521
523
[frame .FrameContentSequence [0 ].DimensionIndexValues
522
524
for frame in self .frames ])
@@ -540,15 +542,15 @@ def image_shape(self):
540
542
# Store frame indices
541
543
self ._frame_indices = frame_indices
542
544
if n_dim < 4 : # 3D volume
543
- return rows , cols , self . _nframes
545
+ return rows , cols , n_frames
544
546
# More than 3 dimensions
545
547
ns_unique = [len (np .unique (row )) for row in self ._frame_indices .T ]
546
- if len (ns_unique ) == 3 :
548
+ if len (ns_unique ) == 3 and has_derived :
547
549
# derived volume is included
548
550
ns_unique .pop (1 )
549
551
shape = (rows , cols ) + tuple (ns_unique )
550
552
n_vols = np .prod (shape [3 :])
551
- if self ._nframes != n_vols * shape [2 ]:
553
+ if n_frames == self .get ( 'NumberOfFrames' ) and n_frames != n_vols * shape [2 ]:
552
554
raise WrapperError ("Calculated shape does not match number of "
553
555
"frames." )
554
556
return tuple (shape )
0 commit comments