diff --git a/sdcflows/utils/tests/test_tools.py b/sdcflows/utils/tests/test_tools.py index 3b433faf23..7e700aec8f 100644 --- a/sdcflows/utils/tests/test_tools.py +++ b/sdcflows/utils/tests/test_tools.py @@ -23,7 +23,7 @@ """Test EPI manipulation routines.""" import numpy as np import nibabel as nb -from ..tools import brain_masker +from sdcflows.utils.tools import brain_masker, deoblique_and_zooms def test_epi_mask(tmpdir, testdata_dir): @@ -31,3 +31,42 @@ def test_epi_mask(tmpdir, testdata_dir): tmpdir.chdir() mask = brain_masker(testdata_dir / "epi.nii.gz")[-1] assert abs(np.asanyarray(nb.load(mask).dataobj).sum() - 166476) < 10 + + +def test_deoblique_and_zooms(): + """Check deoblique and denser.""" + + # Generate an example reference image + ref_data = np.zeros((20, 30, 40), dtype=np.float32) + ref_affine = np.eye(4) + ref_affine[:3, :3] = np.diag([2, 3, 4]) # Set zooms to (2, 3, 4) + ref_img = nb.Nifti1Image(ref_data, ref_affine) + + # Generate an example oblique image + ob_data = np.zeros((25, 35, 45), dtype=np.float32) + ob_affine = np.eye(4) + + # Rotate 90 degrees around x-axis + ob_affine[:3, :3] = np.array([[0, 1, 0], [0, 0, 1], [1, 0, 0]]) + ob_img = nb.Nifti1Image(ob_data, ob_affine) + + # Call function with default parameters + out_img = deoblique_and_zooms(ref_img, ob_img) + + # Check output shape and zooms + assert out_img.shape == (26, 36, 46) + assert np.allclose(out_img.header.get_zooms()[:3], (0.5, 1.0, 1.0)) + + # Call function with larger padding + out_img = deoblique_and_zooms(ref_img, ob_img, padding=3) + + # Check output shape and zooms + assert out_img.shape == (32, 42, 52) + assert np.allclose(out_img.header.get_zooms()[:3], (0.4, 0.75, 0.8)) + + # Call function with larger factor + out_img = deoblique_and_zooms(ref_img, ob_img, factor=8) + + # Check output shape and zooms + assert out_img.shape == (160, 240, 320) + assert np.allclose(out_img.header.get_zooms()[:3], (0.025, 0.0125, 0.0125))