Skip to content

Commit 0de33b6

Browse files
committed
Use SimpleITK for constant field test
1 parent 9f916e4 commit 0de33b6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

nitransforms/tests/test_nonlinear.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
from subprocess import check_call
77
import shutil
8+
9+
import SimpleITK as sitk
810
import pytest
911

1012
import numpy as np
@@ -289,9 +291,15 @@ def test_constant_field_vs_ants(tmp_path):
289291
field[..., 2] = 5
290292

291293
field_img = nb.Nifti1Image(field, ref_affine)
292-
itk_img = ITKDisplacementsField.to_image(field_img)
294+
293295
warpfile = tmp_path / "const_disp.nii.gz"
294-
itk_img.to_filename(warpfile)
296+
itk_img = sitk.GetImageFromArray(field, isVector=True)
297+
itk_img.SetOrigin(tuple(ref_affine[:3, 3]))
298+
zooms = np.sqrt((ref_affine[:3, :3] ** 2).sum(0))
299+
itk_img.SetSpacing(tuple(zooms))
300+
direction = (ref_affine[:3, :3] / zooms).ravel()
301+
itk_img.SetDirection(tuple(direction))
302+
sitk.WriteImage(itk_img, str(warpfile))
295303

296304
points = np.array([[0.0, 0.0, 0.0], [1.0, 2.0, 3.0]])
297305
csvin = tmp_path / "points.csv"
@@ -307,7 +315,7 @@ def test_constant_field_vs_ants(tmp_path):
307315
ants_res = np.genfromtxt(csvout, delimiter=",", names=True)
308316
ants_pts = np.vstack([ants_res[n] for n in ("x", "y", "z")]).T
309317

310-
xfm = DenseFieldTransform(warpfile)
318+
xfm = DenseFieldTransform(field_img)
311319
mapped = xfm.map(points)
312320

313321
assert not np.allclose(mapped, ants_pts, atol=1e-6)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ test = [
4141
"pytest-xdist >= 2.5",
4242
"coverage[toml] >= 5.2.1",
4343
"nitransforms[niftiext]",
44+
"SimpleITK",
4445
]
4546
# Aliases
4647
niftiexts = ["nitransforms[niftiext]"]

0 commit comments

Comments
 (0)