14
14
15
15
import nibabel as nb
16
16
import numpy as np
17
- from scipy .ndimage .morphology import binary_erosion
18
- from scipy .spatial .distance import cdist , euclidean , dice , jaccard
19
- from scipy .ndimage .measurements import center_of_mass , label
20
17
21
18
from .. import config , logging
22
19
@@ -74,6 +71,7 @@ class Distance(BaseInterface):
74
71
_hist_filename = "hist.pdf"
75
72
76
73
def _find_border (self , data ):
74
+ from scipy .ndimage .morphology import binary_erosion
77
75
eroded = binary_erosion (data )
78
76
border = np .logical_and (data , np .logical_not (eroded ))
79
77
return border
@@ -87,6 +85,7 @@ def _get_coordinates(self, data, affine):
87
85
return coordinates [:3 , :]
88
86
89
87
def _eucl_min (self , nii1 , nii2 ):
88
+ from scipy .spatial .distance import cdist , euclidean
90
89
origdata1 = nii1 .get_data ().astype (np .bool )
91
90
border1 = self ._find_border (origdata1 )
92
91
@@ -105,6 +104,8 @@ def _eucl_min(self, nii1, nii2):
105
104
set1_coordinates .T [point1 , :], set2_coordinates .T [point2 , :])
106
105
107
106
def _eucl_cog (self , nii1 , nii2 ):
107
+ from scipy .spatial .distance import cdist
108
+ from scipy .ndimage .measurements import center_of_mass , label
108
109
origdata1 = np .logical_and (nii1 .get_data () != 0 ,
109
110
np .logical_not (np .isnan (nii1 .get_data ())))
110
111
cog_t = np .array (center_of_mass (origdata1 .copy ())).reshape (- 1 , 1 )
@@ -128,6 +129,7 @@ def _eucl_cog(self, nii1, nii2):
128
129
return np .mean (dist_matrix )
129
130
130
131
def _eucl_mean (self , nii1 , nii2 , weighted = False ):
132
+ from scipy .spatial .distance import cdist
131
133
origdata1 = nii1 .get_data ().astype (np .bool )
132
134
border1 = self ._find_border (origdata1 )
133
135
@@ -154,6 +156,7 @@ def _eucl_mean(self, nii1, nii2, weighted=False):
154
156
return np .mean (min_dist_matrix )
155
157
156
158
def _eucl_max (self , nii1 , nii2 ):
159
+ from scipy .spatial .distance import cdist
157
160
origdata1 = nii1 .get_data ()
158
161
origdata1 = np .logical_not (
159
162
np .logical_or (origdata1 == 0 , np .isnan (origdata1 )))
@@ -287,6 +290,7 @@ class Overlap(BaseInterface):
287
290
output_spec = OverlapOutputSpec
288
291
289
292
def _bool_vec_dissimilarity (self , booldata1 , booldata2 , method ):
293
+ from scipy .spatial .distance import dice , jaccard
290
294
methods = {'dice' : dice , 'jaccard' : jaccard }
291
295
if not (np .any (booldata1 ) or np .any (booldata2 )):
292
296
return 0
0 commit comments