Skip to content

Commit 249a2d6

Browse files
author
smoia
committed
Added test for AFNI nonlinear
1 parent ed7e8ad commit 249a2d6

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed
Binary file not shown.

nitransforms/tests/test_nonlinear.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
from ..io.base import TransformFileError
1212
from ..nonlinear import DisplacementsFieldTransform
1313
from ..io.itk import ITKDisplacementsField
14+
from ..io.afni import AFNIDisplacementsField
1415

1516
TESTS_BORDER_TOLERANCE = 0.05
1617
APPLY_NONLINEAR_CMD = {
1718
'itk': """\
1819
antsApplyTransforms -d 3 -r {reference} -i {moving} \
1920
-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
2025
""".format,
2126
}
2227

@@ -47,7 +52,7 @@ def test_itk_disp_load_intent():
4752

4853

4954
@pytest.mark.parametrize('image_orientation', ['RAS', 'LAS', 'LPS', 'oblique'])
50-
@pytest.mark.parametrize('sw_tool', ['itk'])
55+
@pytest.mark.parametrize('sw_tool', ['itk', 'afni'])
5156
@pytest.mark.parametrize('axis', [0, 1, 2, (0, 1), (1, 2), (0, 1, 2)])
5257
def test_displacements_field1(tmp_path, get_testdata, image_orientation, sw_tool, axis):
5358
"""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
5863
fieldmap[..., axis] = -10.0
5964

6065
_hdr = nii.header.copy()
61-
_hdr.set_intent('vector')
66+
if sw_tool in ('itk', ):
67+
_hdr.set_intent('vector')
6268
_hdr.set_data_dtype('float32')
6369

6470
xfm_fname = 'warp.nii.gz'
6571
field = nb.Nifti1Image(fieldmap, nii.affine, _hdr)
6672
field.to_filename(xfm_fname)
6773

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))
7080

7181
# Then apply the transform and cross-check with software
7282
cmd = APPLY_NONLINEAR_CMD[sw_tool](
@@ -90,15 +100,20 @@ def test_displacements_field1(tmp_path, get_testdata, image_orientation, sw_tool
90100
assert (np.abs(diff) > 1e-3).sum() / diff.size < TESTS_BORDER_TOLERANCE
91101

92102

93-
@pytest.mark.parametrize('sw_tool', ['itk'])
103+
@pytest.mark.parametrize('sw_tool', ['itk', 'afni'])
94104
def test_displacements_field2(tmp_path, data_path, sw_tool):
95105
"""Check a translation-only field on one or more axes, different image orientations."""
96106
os.chdir(str(tmp_path))
97107
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'
99108

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))
102117

103118
# Then apply the transform and cross-check with software
104119
cmd = APPLY_NONLINEAR_CMD[sw_tool](

0 commit comments

Comments
 (0)