14
14
from __future__ import division
15
15
16
16
import operator
17
+ import warnings
17
18
18
19
import numpy as np
19
20
@@ -511,13 +512,20 @@ def image_shape(self):
511
512
if hasattr (first_frame , 'get' ) and first_frame .get ([0x18 , 0x9117 ]):
512
513
# DWI image may include derived isotropic, ADC or trace volume
513
514
# 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
515
+ try :
516
+ self .frames = Sequence (
517
+ frame for frame in self .frames if
518
+ frame .MRDiffusionSequence [0 ].DiffusionDirectionality
519
+ != 'ISOTROPIC'
520
+ )
521
+ n_frames = len (self .frames )
522
+ has_derived = True
523
+ except IndexError :
524
+ # Sequence tag is found but missing items!
525
+ raise WrapperError ("Diffusion file missing information" )
526
+ except AttributeError :
527
+ # DiffusionDirectionality tag is not required
528
+ pass
521
529
assert len (self .frames ) == n_frames
522
530
frame_indices = np .array (
523
531
[frame .FrameContentSequence [0 ].DimensionIndexValues
@@ -536,6 +544,9 @@ def image_shape(self):
536
544
if stackid_tag in dim_seq :
537
545
stackid_dim_idx = dim_seq .index (stackid_tag )
538
546
frame_indices = np .delete (frame_indices , stackid_dim_idx , axis = 1 )
547
+ if has_derived :
548
+ # derived volume is included
549
+ frame_indices = np .delete (frame_indices , 1 , axis = 1 )
539
550
# account for the 2 additional dimensions (row and column) not included
540
551
# in the indices
541
552
n_dim = frame_indices .shape [1 ] + 2
@@ -545,9 +556,6 @@ def image_shape(self):
545
556
return rows , cols , n_frames
546
557
# More than 3 dimensions
547
558
ns_unique = [len (np .unique (row )) for row in self ._frame_indices .T ]
548
- if len (ns_unique ) == 3 and has_derived :
549
- # derived volume is included
550
- ns_unique .pop (1 )
551
559
shape = (rows , cols ) + tuple (ns_unique )
552
560
n_vols = np .prod (shape [3 :])
553
561
if n_frames != n_vols * shape [2 ]:
0 commit comments