@@ -89,10 +89,10 @@ def _get_coordinates(self, data, affine):
8989 def _eucl_min (self , nii1 , nii2 ):
9090 from scipy .spatial .distance import cdist , euclidean
9191
92- origdata1 = nii1 . get_data ( ).astype (np .bool )
92+ origdata1 = np . asanyarray ( nii1 . dataobj ).astype (np .bool )
9393 border1 = self ._find_border (origdata1 )
9494
95- origdata2 = nii2 . get_data ( ).astype (np .bool )
95+ origdata2 = np . asanyarray ( nii2 . dataobj ).astype (np .bool )
9696 border2 = self ._find_border (origdata2 )
9797
9898 set1_coordinates = self ._get_coordinates (border1 , nii1 .affine )
@@ -111,16 +111,14 @@ def _eucl_cog(self, nii1, nii2):
111111 from scipy .spatial .distance import cdist
112112 from scipy .ndimage .measurements import center_of_mass , label
113113
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 )
118117 cog_t = np .vstack ((cog_t , np .array ([1 ])))
119118 cog_t_coor = np .dot (nii1 .affine , cog_t )[:3 , :]
120119
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 )
124122 (labeled_data , n_labels ) = label (origdata2 )
125123
126124 cogs = np .ones ((4 , n_labels ))
@@ -137,10 +135,10 @@ def _eucl_cog(self, nii1, nii2):
137135 def _eucl_mean (self , nii1 , nii2 , weighted = False ):
138136 from scipy .spatial .distance import cdist
139137
140- origdata1 = nii1 . get_data ( ).astype (np .bool )
138+ origdata1 = np . asanyarray ( nii1 . dataobj ).astype (np .bool )
141139 border1 = self ._find_border (origdata1 )
142140
143- origdata2 = nii2 . get_data ( ).astype (np .bool )
141+ origdata2 = np . asanyarray ( nii2 . dataobj ).astype (np .bool )
144142
145143 set1_coordinates = self ._get_coordinates (border1 , nii1 .affine )
146144 set2_coordinates = self ._get_coordinates (origdata2 , nii2 .affine )
@@ -159,26 +157,26 @@ def _eucl_mean(self, nii1, nii2, weighted=False):
159157 plt .close ()
160158
161159 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 )
163161 else :
164162 return np .mean (min_dist_matrix )
165163
166164 def _eucl_max (self , nii1 , nii2 ):
167165 from scipy .spatial .distance import cdist
168166
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 )
173171
174172 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 )
177175 origdata1 = np .logical_and (maskdata , origdata1 )
178176 origdata2 = np .logical_and (maskdata , origdata2 )
179177
180178 if origdata1 .max () == 0 or origdata2 .max () == 0 :
181- return np .NaN
179+ return np .nan
182180
183181 border1 = self ._find_border (origdata1 )
184182 border2 = self ._find_border (origdata2 )
@@ -302,19 +300,17 @@ def _run_interface(self, runtime):
302300 scale = 1.0
303301
304302 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 ])
308304
309- data1 = nii1 . get_data ( )
305+ data1 = np . asanyarray ( nii1 . dataobj )
310306 data1 [np .logical_or (data1 < 0 , np .isnan (data1 ))] = 0
311307 max1 = int (data1 .max ())
312308 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 ))
314310 data2 [np .logical_or (data1 < 0 , np .isnan (data1 ))] = 0
315311
316312 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 )
318314 maskdata = ~ np .logical_or (maskdata == 0 , np .isnan (maskdata ))
319315 data1 [~ maskdata ] = 0
320316 data2 [~ maskdata ] = 0
@@ -445,8 +441,8 @@ class FuzzyOverlap(SimpleInterface):
445441
446442 def _run_interface (self , runtime ):
447443 # 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
450446
451447 # Data must have same shape
452448 if not refdata .shape == tstdata .shape :
@@ -460,8 +456,7 @@ def _run_interface(self, runtime):
460456 # Load mask
461457 mask = np .ones_like (refdata , dtype = bool )
462458 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
465460 mask = np .repeat (mask [..., np .newaxis ], ncomp , - 1 )
466461 assert mask .shape == refdata .shape
467462
@@ -565,8 +560,8 @@ class ErrorMap(BaseInterface):
565560 def _run_interface (self , runtime ):
566561 # Get two numpy data matrices
567562 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 )
570565 assert ref_data .ndim == tst_data .ndim
571566
572567 # Load mask
@@ -578,7 +573,7 @@ def _run_interface(self, runtime):
578573 mapshape = ref_data .shape [:- 1 ]
579574
580575 if isdefined (self .inputs .mask ):
581- msk = nb .load (self .inputs .mask ).get_data ( )
576+ msk = np . asanyarray ( nb .load (self .inputs .mask ).dataobj )
582577 if mapshape != msk .shape :
583578 raise RuntimeError (
584579 "Mask should match volume shape, \
@@ -701,7 +696,7 @@ def _run_interface(self, runtime):
701696 vol1_nii = nb .load (self .inputs .volume1 )
702697 vol2_nii = nb .load (self .inputs .volume2 )
703698
704- dims = vol1_nii .get_data (). ndim
699+ dims = len ( vol1_nii .shape )
705700
706701 if dims == 3 or dims == 2 :
707702 vols1 = [vol1_nii ]
@@ -716,12 +711,12 @@ def _run_interface(self, runtime):
716711 )
717712
718713 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
720715 else :
721716 mask1 = None
722717
723718 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
725720 else :
726721 mask2 = None
727722
0 commit comments