11
11
from ..io .base import TransformFileError
12
12
from ..nonlinear import DisplacementsFieldTransform
13
13
from ..io .itk import ITKDisplacementsField
14
+ from ..io .afni import AFNIDisplacementsField
14
15
15
16
TESTS_BORDER_TOLERANCE = 0.05
16
17
APPLY_NONLINEAR_CMD = {
17
18
'itk' : """\
18
19
antsApplyTransforms -d 3 -r {reference} -i {moving} \
19
20
-o resampled.nii.gz -n NearestNeighbor -t {transform} --float\
21
+ """ .format ,
22
+ 'afni' : """\
23
+ 3dNwarpApply -nwarp {transform} -source {moving} \
24
+ -master {reference} -interp NN -prefix resampled.nii.gz
20
25
""" .format ,
21
26
}
22
27
@@ -47,7 +52,7 @@ def test_itk_disp_load_intent():
47
52
48
53
49
54
@pytest .mark .parametrize ('image_orientation' , ['RAS' , 'LAS' , 'LPS' , 'oblique' ])
50
- @pytest .mark .parametrize ('sw_tool' , ['itk' ])
55
+ @pytest .mark .parametrize ('sw_tool' , ['itk' , 'afni' ])
51
56
@pytest .mark .parametrize ('axis' , [0 , 1 , 2 , (0 , 1 ), (1 , 2 ), (0 , 1 , 2 )])
52
57
def test_displacements_field1 (tmp_path , get_testdata , image_orientation , sw_tool , axis ):
53
58
"""Check a translation-only field on one or more axes, different image orientations."""
@@ -58,15 +63,20 @@ def test_displacements_field1(tmp_path, get_testdata, image_orientation, sw_tool
58
63
fieldmap [..., axis ] = - 10.0
59
64
60
65
_hdr = nii .header .copy ()
61
- _hdr .set_intent ('vector' )
66
+ if sw_tool in ('itk' , ):
67
+ _hdr .set_intent ('vector' )
62
68
_hdr .set_data_dtype ('float32' )
63
69
64
70
xfm_fname = 'warp.nii.gz'
65
71
field = nb .Nifti1Image (fieldmap , nii .affine , _hdr )
66
72
field .to_filename (xfm_fname )
67
73
68
- xfm = DisplacementsFieldTransform (
69
- ITKDisplacementsField .from_image (field ))
74
+ if sw_tool == 'itk' :
75
+ xfm = DisplacementsFieldTransform (
76
+ ITKDisplacementsField .from_image (field ))
77
+ elif sw_tool == 'afni' :
78
+ xfm = DisplacementsFieldTransform (
79
+ AFNIDisplacementField .from_image (field ))
70
80
71
81
# Then apply the transform and cross-check with software
72
82
cmd = APPLY_NONLINEAR_CMD [sw_tool ](
@@ -90,15 +100,20 @@ def test_displacements_field1(tmp_path, get_testdata, image_orientation, sw_tool
90
100
assert (np .abs (diff ) > 1e-3 ).sum () / diff .size < TESTS_BORDER_TOLERANCE
91
101
92
102
93
- @pytest .mark .parametrize ('sw_tool' , ['itk' ])
103
+ @pytest .mark .parametrize ('sw_tool' , ['itk' , 'afni' ])
94
104
def test_displacements_field2 (tmp_path , data_path , sw_tool ):
95
105
"""Check a translation-only field on one or more axes, different image orientations."""
96
106
os .chdir (str (tmp_path ))
97
107
img_fname = data_path / 'tpl-OASIS30ANTs_T1w.nii.gz'
98
- xfm_fname = data_path / 'ds-005_sub-01_from-OASIS_to-T1_warp.nii.gz'
99
108
100
- xfm = DisplacementsFieldTransform (
101
- ITKDisplacementsField .from_filename (xfm_fname ))
109
+ if sw_tool == 'itk' :
110
+ xfm_fname = data_path / 'ds-005_sub-01_from-OASIS_to-T1_warp.nii.gz'
111
+ xfm = DisplacementsFieldTransform (
112
+ ITKDisplacementsField .from_image (field ))
113
+ elif sw_tool == 'afni' :
114
+ xfm_fname = data_path / 'itk_into_afni.nii.gz'
115
+ xfm = DisplacementsFieldTransform (
116
+ AFNIDisplacementField .from_image (field ))
102
117
103
118
# Then apply the transform and cross-check with software
104
119
cmd = APPLY_NONLINEAR_CMD [sw_tool ](
0 commit comments