@@ -89,10 +89,10 @@ def _get_coordinates(self, data, affine):
89
89
def _eucl_min (self , nii1 , nii2 ):
90
90
from scipy .spatial .distance import cdist , euclidean
91
91
92
- origdata1 = nii1 . get_data ( ).astype (np .bool )
92
+ origdata1 = np . asanyarray ( nii1 . dataobj ).astype (np .bool )
93
93
border1 = self ._find_border (origdata1 )
94
94
95
- origdata2 = nii2 . get_data ( ).astype (np .bool )
95
+ origdata2 = np . asanyarray ( nii2 . dataobj ).astype (np .bool )
96
96
border2 = self ._find_border (origdata2 )
97
97
98
98
set1_coordinates = self ._get_coordinates (border1 , nii1 .affine )
@@ -111,16 +111,14 @@ def _eucl_cog(self, nii1, nii2):
111
111
from scipy .spatial .distance import cdist
112
112
from scipy .ndimage .measurements import center_of_mass , label
113
113
114
- origdata1 = np .logical_and (
115
- nii1 .get_data () != 0 , np .logical_not (np .isnan (nii1 .get_data ()))
116
- )
117
- cog_t = np .array (center_of_mass (origdata1 .copy ())).reshape (- 1 , 1 )
114
+ origdata1 = np .asanyarray (nii1 .dataobj )
115
+ origdata1 = (np .rint (origdata1 ) != 0 ) & ~ np .isnan (origdata1 )
116
+ cog_t = np .array (center_of_mass (origdata1 )).reshape (- 1 , 1 )
118
117
cog_t = np .vstack ((cog_t , np .array ([1 ])))
119
118
cog_t_coor = np .dot (nii1 .affine , cog_t )[:3 , :]
120
119
121
- origdata2 = np .logical_and (
122
- nii2 .get_data () != 0 , np .logical_not (np .isnan (nii2 .get_data ()))
123
- )
120
+ origdata2 = np .asanyarray (nii2 .dataobj )
121
+ origdata2 = (np .rint (origdata2 ) != 0 ) & ~ np .isnan (origdata2 )
124
122
(labeled_data , n_labels ) = label (origdata2 )
125
123
126
124
cogs = np .ones ((4 , n_labels ))
@@ -137,10 +135,10 @@ def _eucl_cog(self, nii1, nii2):
137
135
def _eucl_mean (self , nii1 , nii2 , weighted = False ):
138
136
from scipy .spatial .distance import cdist
139
137
140
- origdata1 = nii1 . get_data ( ).astype (np .bool )
138
+ origdata1 = np . asanyarray ( nii1 . dataobj ).astype (np .bool )
141
139
border1 = self ._find_border (origdata1 )
142
140
143
- origdata2 = nii2 . get_data ( ).astype (np .bool )
141
+ origdata2 = np . asanyarray ( nii2 . dataobj ).astype (np .bool )
144
142
145
143
set1_coordinates = self ._get_coordinates (border1 , nii1 .affine )
146
144
set2_coordinates = self ._get_coordinates (origdata2 , nii2 .affine )
@@ -159,26 +157,26 @@ def _eucl_mean(self, nii1, nii2, weighted=False):
159
157
plt .close ()
160
158
161
159
if weighted :
162
- return np .average (min_dist_matrix , weights = nii2 .get_data () [origdata2 ].flat )
160
+ return np .average (min_dist_matrix , weights = nii2 .dataobj [origdata2 ].flat )
163
161
else :
164
162
return np .mean (min_dist_matrix )
165
163
166
164
def _eucl_max (self , nii1 , nii2 ):
167
165
from scipy .spatial .distance import cdist
168
166
169
- origdata1 = nii1 . get_data ( )
170
- origdata1 = np . logical_not (np .logical_or (origdata1 == 0 , np .isnan (origdata1 )) )
171
- origdata2 = nii2 . get_data ( )
172
- origdata2 = np . logical_not (np .logical_or (origdata2 == 0 , np .isnan (origdata2 )) )
167
+ origdata1 = np . asanyarray ( nii1 . dataobj )
168
+ origdata1 = (np .rint (origdata1 ) != 0 ) & ~ np .isnan (origdata1 )
169
+ origdata2 = np . asanyarray ( nii2 . dataobj )
170
+ origdata2 = (np .rint (origdata2 ) != 0 ) & ~ np .isnan (origdata2 )
173
171
174
172
if isdefined (self .inputs .mask_volume ):
175
- maskdata = nb .load (self .inputs .mask_volume ).get_data ( )
176
- maskdata = np . logical_not (np .logical_or (maskdata == 0 , np .isnan (maskdata )) )
173
+ maskdata = np . asanyarray ( nb .load (self .inputs .mask_volume ).dataobj )
174
+ maskdata = (np .rint (maskdata ) != 0 ) & ~ np .isnan (maskdata )
177
175
origdata1 = np .logical_and (maskdata , origdata1 )
178
176
origdata2 = np .logical_and (maskdata , origdata2 )
179
177
180
178
if origdata1 .max () == 0 or origdata2 .max () == 0 :
181
- return np .NaN
179
+ return np .nan
182
180
183
181
border1 = self ._find_border (origdata1 )
184
182
border2 = self ._find_border (origdata2 )
@@ -302,19 +300,17 @@ def _run_interface(self, runtime):
302
300
scale = 1.0
303
301
304
302
if self .inputs .vol_units == "mm" :
305
- voxvol = nii1 .header .get_zooms ()
306
- for i in range (nii1 .get_data ().ndim - 1 ):
307
- scale = scale * voxvol [i ]
303
+ scale = np .prod (nii1 .header .get_zooms ()[:3 ])
308
304
309
- data1 = nii1 . get_data ( )
305
+ data1 = np . asanyarray ( nii1 . dataobj )
310
306
data1 [np .logical_or (data1 < 0 , np .isnan (data1 ))] = 0
311
307
max1 = int (data1 .max ())
312
308
data1 = data1 .astype (np .min_scalar_type (max1 ))
313
- data2 = nii2 . get_data ( ).astype (np .min_scalar_type (max1 ))
309
+ data2 = np . asanyarray ( nii2 . dataobj ).astype (np .min_scalar_type (max1 ))
314
310
data2 [np .logical_or (data1 < 0 , np .isnan (data1 ))] = 0
315
311
316
312
if isdefined (self .inputs .mask_volume ):
317
- maskdata = nb .load (self .inputs .mask_volume ).get_data ( )
313
+ maskdata = np . asanyarray ( nb .load (self .inputs .mask_volume ).dataobj )
318
314
maskdata = ~ np .logical_or (maskdata == 0 , np .isnan (maskdata ))
319
315
data1 [~ maskdata ] = 0
320
316
data2 [~ maskdata ] = 0
@@ -445,8 +441,8 @@ class FuzzyOverlap(SimpleInterface):
445
441
446
442
def _run_interface (self , runtime ):
447
443
# Load data
448
- refdata = nb .concat_images (self .inputs .in_ref ).get_data ()
449
- tstdata = nb .concat_images (self .inputs .in_tst ).get_data ()
444
+ refdata = nb .concat_images (self .inputs .in_ref ).dataobj
445
+ tstdata = nb .concat_images (self .inputs .in_tst ).dataobj
450
446
451
447
# Data must have same shape
452
448
if not refdata .shape == tstdata .shape :
@@ -460,8 +456,7 @@ def _run_interface(self, runtime):
460
456
# Load mask
461
457
mask = np .ones_like (refdata , dtype = bool )
462
458
if isdefined (self .inputs .in_mask ):
463
- mask = nb .load (self .inputs .in_mask ).get_data ()
464
- mask = mask > 0
459
+ mask = np .asanyarray (nb .load (self .inputs .in_mask ).dataobj ) > 0
465
460
mask = np .repeat (mask [..., np .newaxis ], ncomp , - 1 )
466
461
assert mask .shape == refdata .shape
467
462
@@ -565,8 +560,8 @@ class ErrorMap(BaseInterface):
565
560
def _run_interface (self , runtime ):
566
561
# Get two numpy data matrices
567
562
nii_ref = nb .load (self .inputs .in_ref )
568
- ref_data = np .squeeze (nii_ref .get_data () )
569
- tst_data = np .squeeze (nb .load (self .inputs .in_tst ).get_data () )
563
+ ref_data = np .squeeze (nii_ref .dataobj )
564
+ tst_data = np .squeeze (nb .load (self .inputs .in_tst ).dataobj )
570
565
assert ref_data .ndim == tst_data .ndim
571
566
572
567
# Load mask
@@ -578,7 +573,7 @@ def _run_interface(self, runtime):
578
573
mapshape = ref_data .shape [:- 1 ]
579
574
580
575
if isdefined (self .inputs .mask ):
581
- msk = nb .load (self .inputs .mask ).get_data ( )
576
+ msk = np . asanyarray ( nb .load (self .inputs .mask ).dataobj )
582
577
if mapshape != msk .shape :
583
578
raise RuntimeError (
584
579
"Mask should match volume shape, \
@@ -701,7 +696,7 @@ def _run_interface(self, runtime):
701
696
vol1_nii = nb .load (self .inputs .volume1 )
702
697
vol2_nii = nb .load (self .inputs .volume2 )
703
698
704
- dims = vol1_nii .get_data (). ndim
699
+ dims = len ( vol1_nii .shape )
705
700
706
701
if dims == 3 or dims == 2 :
707
702
vols1 = [vol1_nii ]
@@ -716,12 +711,12 @@ def _run_interface(self, runtime):
716
711
)
717
712
718
713
if isdefined (self .inputs .mask1 ):
719
- mask1 = nb .load (self .inputs .mask1 ).get_data ( ) == 1
714
+ mask1 = np . asanyarray ( nb .load (self .inputs .mask1 ).dataobj ) == 1
720
715
else :
721
716
mask1 = None
722
717
723
718
if isdefined (self .inputs .mask2 ):
724
- mask2 = nb .load (self .inputs .mask2 ).get_data ( ) == 1
719
+ mask2 = np . asanyarray ( nb .load (self .inputs .mask2 ).dataobj ) == 1
725
720
else :
726
721
mask2 = None
727
722
0 commit comments