|
8 | 8 |
|
9 | 9 | import numpy as np
|
10 | 10 | import nibabel as nb
|
11 |
| -from ..manip import load as _load |
| 11 | +from ..manip import load as _load, TransformChain |
| 12 | +from ..linear import Affine |
12 | 13 | from .test_nonlinear import (
|
13 | 14 | TESTS_BORDER_TOLERANCE,
|
14 | 15 | APPLY_NONLINEAR_CMD,
|
15 | 16 | )
|
16 | 17 |
|
| 18 | +FMT = {"lta": "fs", "tfm": "itk"} |
| 19 | + |
17 | 20 |
|
18 | 21 | def test_itk_h5(tmp_path, testdata_path):
|
19 | 22 | """Check a translation-only field on one or more axes, different image orientations."""
|
@@ -51,3 +54,22 @@ def test_itk_h5(tmp_path, testdata_path):
|
51 | 54 | diff = sw_moved.get_fdata() - nt_moved.get_fdata()
|
52 | 55 | # A certain tolerance is necessary because of resampling at borders
|
53 | 56 | assert (np.abs(diff) > 1e-3).sum() / diff.size < TESTS_BORDER_TOLERANCE
|
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.parametrize("ext0", ["lta", "tfm"]) |
| 60 | +@pytest.mark.parametrize("ext1", ["lta", "tfm"]) |
| 61 | +@pytest.mark.parametrize("ext2", ["lta", "tfm"]) |
| 62 | +def test_collapse_affines(tmp_path, data_path, ext0, ext1, ext2): |
| 63 | + """Check whether affines are correctly collapsed.""" |
| 64 | + chain = TransformChain([ |
| 65 | + Affine.from_filename(data_path / "regressions" |
| 66 | + / f"from-fsnative_to-scanner_mode-image.{ext0}", fmt=f"{FMT[ext0]}"), |
| 67 | + Affine.from_filename(data_path / "regressions" |
| 68 | + / f"from-scanner_to-bold_mode-image.{ext1}", fmt=f"{FMT[ext1]}"), |
| 69 | + ]) |
| 70 | + assert np.allclose( |
| 71 | + chain.asaffine().matrix, |
| 72 | + Affine.from_filename( |
| 73 | + data_path / "regressions" / f"from-fsnative_to-bold_mode-image.{ext2}", |
| 74 | + fmt=f"{FMT[ext2]}").matrix, |
| 75 | + ) |
0 commit comments