29
29
3dNwarpApply -nwarp {transform} -source {moving} \
30
30
-master {reference} -interp NN -prefix {output} {extra}\
31
31
""" .format ,
32
- ' fsl' : """\
32
+ " fsl" : """\
33
33
applywarp -i {moving} -r {reference} -o {output} {extra}\
34
34
-w {transform} --interp=nn""" .format ,
35
35
}
39
39
def test_itk_disp_load (size ):
40
40
"""Checks field sizes."""
41
41
with pytest .raises (TransformFileError ):
42
- ITKDisplacementsField .from_image (nb .Nifti1Image (np .zeros (size ), np .eye (4 ), None ))
42
+ ITKDisplacementsField .from_image (
43
+ nb .Nifti1Image (np .zeros (size ), np .eye (4 ), None )
44
+ )
43
45
44
46
45
47
@pytest .mark .parametrize ("size" , [(20 , 20 , 20 ), (20 , 20 , 20 , 2 , 3 ), (20 , 20 , 20 , 1 , 4 )])
@@ -98,15 +100,16 @@ def test_bsplines_references(testdata_path):
98
100
99
101
with pytest .raises (TransformError ):
100
102
apply (
101
- BSplineFieldTransform (testdata_path / "someones_bspline_coefficients.nii.gz" ),
103
+ BSplineFieldTransform (
104
+ testdata_path / "someones_bspline_coefficients.nii.gz"
105
+ ),
102
106
testdata_path / "someones_anatomy.nii.gz" ,
103
107
)
104
108
105
109
apply (
106
- BSplineFieldTransform (
107
- testdata_path / "someones_bspline_coefficients.nii.gz" ),
110
+ BSplineFieldTransform (testdata_path / "someones_bspline_coefficients.nii.gz" ),
108
111
testdata_path / "someones_anatomy.nii.gz" ,
109
- reference = testdata_path / "someones_anatomy.nii.gz"
112
+ reference = testdata_path / "someones_anatomy.nii.gz" ,
110
113
)
111
114
112
115
@@ -170,7 +173,7 @@ def test_displacements_field1(
170
173
nt_moved_mask .set_data_dtype (msk .get_data_dtype ())
171
174
diff = np .asanyarray (sw_moved_mask .dataobj ) - np .asanyarray (nt_moved_mask .dataobj )
172
175
173
- assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL
176
+ assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL
174
177
brainmask = np .asanyarray (nt_moved_mask .dataobj , dtype = bool )
175
178
176
179
# Then apply the transform and cross-check with software
@@ -179,7 +182,7 @@ def test_displacements_field1(
179
182
reference = tmp_path / "reference.nii.gz" ,
180
183
moving = tmp_path / "reference.nii.gz" ,
181
184
output = tmp_path / "resampled.nii.gz" ,
182
- extra = "--output-data-type uchar" if sw_tool == "itk" else ""
185
+ extra = "--output-data-type uchar" if sw_tool == "itk" else "" ,
183
186
)
184
187
185
188
exit_code = check_call ([cmd ], shell = True )
@@ -190,10 +193,9 @@ def test_displacements_field1(
190
193
nt_moved .set_data_dtype (nii .get_data_dtype ())
191
194
nt_moved .to_filename ("nt_resampled.nii.gz" )
192
195
sw_moved .set_data_dtype (nt_moved .get_data_dtype ())
193
- diff = (
194
- np .asanyarray (sw_moved .dataobj , dtype = sw_moved .get_data_dtype ())
195
- - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
196
- )
196
+ diff = np .asanyarray (
197
+ sw_moved .dataobj , dtype = sw_moved .get_data_dtype ()
198
+ ) - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
197
199
# A certain tolerance is necessary because of resampling at borders
198
200
assert np .sqrt ((diff [brainmask ] ** 2 ).mean ()) < RMSE_TOL
199
201
@@ -230,12 +232,11 @@ def test_displacements_field2(tmp_path, testdata_path, sw_tool):
230
232
nt_moved = xfm .apply (img_fname , order = 0 )
231
233
nt_moved .to_filename ("nt_resampled.nii.gz" )
232
234
sw_moved .set_data_dtype (nt_moved .get_data_dtype ())
233
- diff = (
234
- np .asanyarray (sw_moved .dataobj , dtype = sw_moved .get_data_dtype ())
235
- - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
236
- )
235
+ diff = np .asanyarray (
236
+ sw_moved .dataobj , dtype = sw_moved .get_data_dtype ()
237
+ ) - np .asanyarray (nt_moved .dataobj , dtype = nt_moved .get_data_dtype ())
237
238
# A certain tolerance is necessary because of resampling at borders
238
- assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL
239
+ assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL
239
240
240
241
241
242
def test_bspline (tmp_path , testdata_path ):
@@ -249,12 +250,16 @@ def test_bspline(tmp_path, testdata_path):
249
250
bsplxfm = BSplineFieldTransform (bs_name , reference = img_name )
250
251
dispxfm = DenseFieldTransform (disp_name )
251
252
252
- out_disp = apply (dispxfm ,img_name )
253
- out_bspl = apply (bsplxfm ,img_name )
253
+ out_disp = apply (dispxfm , img_name )
254
+ out_bspl = apply (bsplxfm , img_name )
254
255
255
256
out_disp .to_filename ("resampled_field.nii.gz" )
256
257
out_bspl .to_filename ("resampled_bsplines.nii.gz" )
257
258
258
- assert np .sqrt (
259
- (out_disp .get_fdata (dtype = "float32" ) - out_bspl .get_fdata (dtype = "float32" )) ** 2
260
- ).mean () < 0.2
259
+ assert (
260
+ np .sqrt (
261
+ (out_disp .get_fdata (dtype = "float32" ) - out_bspl .get_fdata (dtype = "float32" ))
262
+ ** 2
263
+ ).mean ()
264
+ < 0.2
265
+ )
0 commit comments