@@ -150,13 +150,13 @@ def test_apply_linear_transform(
150
150
151
151
152
152
@pytest .mark .xfail (
153
- reason = "Disable while #266 is developed. " ,
153
+ reason = "GH-267: disabled while debugging " ,
154
154
strict = False ,
155
155
)
156
156
@pytest .mark .parametrize ("image_orientation" , ["RAS" , "LAS" , "LPS" , "oblique" ])
157
157
@pytest .mark .parametrize ("sw_tool" , ["itk" , "afni" ])
158
158
@pytest .mark .parametrize ("axis" , [0 , 1 , 2 , (0 , 1 ), (1 , 2 ), (0 , 1 , 2 )])
159
- def test_displacements_field1 (
159
+ def test_apply_displacements_field1 (
160
160
tmp_path ,
161
161
get_testdata ,
162
162
get_testmask ,
@@ -190,16 +190,17 @@ def test_displacements_field1(
190
190
else :
191
191
field .to_filename (xfm_fname )
192
192
193
- xfm = nitnl .load (xfm_fname , fmt = sw_tool )
193
+ # xfm = nitnl.load(xfm_fname, fmt=sw_tool)
194
+ xfm = nitnl .DenseFieldTransform (fieldmap , reference = nii )
194
195
196
+ ants_output = tmp_path / "ants_brainmask.nii.gz"
195
197
# Then apply the transform and cross-check with software
196
198
cmd = APPLY_NONLINEAR_CMD [sw_tool ](
197
199
transform = os .path .abspath (xfm_fname ),
198
200
reference = tmp_path / "mask.nii.gz" ,
199
201
moving = tmp_path / "mask.nii.gz" ,
200
- output = tmp_path / "resampled_brainmask.nii.gz" ,
201
- extra = "" ,
202
- # extra="--output-data-type uchar" if sw_tool == "itk" else "",
202
+ output = ants_output ,
203
+ extra = "--output-data-type uchar" if sw_tool == "itk" else "" ,
203
204
)
204
205
205
206
# skip test if command is not available on host
@@ -209,11 +210,13 @@ def test_displacements_field1(
209
210
210
211
# resample mask
211
212
exit_code = check_call ([cmd ], shell = True )
212
- sw_moved_mask = nb .load ("resampled_brainmask.nii.gz" )
213
+ assert exit_code == 0
214
+ sw_moved_mask = nb .load (ants_output )
213
215
nt_moved_mask = apply (xfm , msk , order = 0 )
214
216
215
- # Calculate xor between both:
216
- sw_mask = np .asanyarray (sw_moved_mask .dataobj , dtype = bool )
217
+ nt_moved_mask .to_filename (tmp_path / "nit_brainmask.nii.gz" )
218
+
219
+ assert np .sqrt ((diff ** 2 ).mean ()) < RMSE_TOL_LINEAR
217
220
brainmask = np .asanyarray (nt_moved_mask .dataobj , dtype = bool )
218
221
percent_diff = (sw_mask != brainmask )[5 :- 5 , 5 :- 5 , 5 :- 5 ].sum () / brainmask .size
219
222
@@ -403,3 +406,33 @@ def test_apply_4d(serialize_4d):
403
406
data = np .asanyarray (moved .dataobj )
404
407
idxs = [tuple (np .argwhere (data [..., i ])[0 ]) for i in range (nvols )]
405
408
assert idxs == [(9 - i , 2 , 2 ) for i in range (nvols )]
409
+
410
+
411
+ @pytest .mark .xfail (
412
+ reason = "GH-267: disabled while debugging" ,
413
+ strict = False ,
414
+ )
415
+ def test_apply_bspline (tmp_path , testdata_path ):
416
+ """Cross-check B-Splines and deformation field."""
417
+ os .chdir (str (tmp_path ))
418
+
419
+ img_name = testdata_path / "someones_anatomy.nii.gz"
420
+ disp_name = testdata_path / "someones_displacement_field.nii.gz"
421
+ bs_name = testdata_path / "someones_bspline_coefficients.nii.gz"
422
+
423
+ bsplxfm = nitnl .BSplineFieldTransform (bs_name , reference = img_name )
424
+ dispxfm = nitnl .DenseFieldTransform (disp_name )
425
+
426
+ out_disp = apply (dispxfm , img_name )
427
+ out_bspl = apply (bsplxfm , img_name )
428
+
429
+ out_disp .to_filename ("resampled_field.nii.gz" )
430
+ out_bspl .to_filename ("resampled_bsplines.nii.gz" )
431
+
432
+ assert (
433
+ np .sqrt (
434
+ (out_disp .get_fdata (dtype = "float32" ) - out_bspl .get_fdata (dtype = "float32" ))
435
+ ** 2
436
+ ).mean ()
437
+ < 0.2
438
+ )
0 commit comments