|
23 | 23 | """Test fieldmap-less SDC-SyN.""" |
24 | 24 |
|
25 | 25 | import json |
| 26 | + |
| 27 | +import numpy as np |
| 28 | +import nibabel as nb |
26 | 29 | import pytest |
27 | 30 | from nipype.pipeline import engine as pe |
28 | 31 |
|
29 | | -from ..syn import init_syn_sdc_wf, init_syn_preprocessing_wf, _adjust_zooms, _set_dtype |
| 32 | +from .... import data |
| 33 | +from ..syn import init_syn_sdc_wf, init_syn_preprocessing_wf, _adjust_zooms, _set_dtype, _mm2vox |
30 | 34 |
|
31 | 35 |
|
32 | 36 | @pytest.mark.veryslow |
@@ -254,3 +258,27 @@ def test_ensure_dtype(in_dtype, out_dtype, tmpdir): |
254 | 258 | assert out_file == f"{in_dtype}.nii.gz" |
255 | 259 | else: |
256 | 260 | assert out_file == f"{in_dtype}_{out_dtype}.nii.gz" |
| 261 | + |
| 262 | + |
| 263 | +def test_mm2vox(tmp_path): |
| 264 | + img = nb.Nifti1Image(np.zeros((10, 10, 10)), np.diag((2, 3, 4, 1))) |
| 265 | + img_file = tmp_path / "test.nii.gz" |
| 266 | + img.to_filename(img_file) |
| 267 | + |
| 268 | + config = json.loads(data.load.readable("sd_syn.json").read_text()) |
| 269 | + |
| 270 | + params = config['transform_parameters'] |
| 271 | + mm_values = np.array([level[2] for level in params]) |
| 272 | + |
| 273 | + vox_params_i = _mm2vox(str(img_file), 'i', config) |
| 274 | + vox_values_i = [level[2] for level in vox_params_i] |
| 275 | + assert [mm_level[:2] == vox_level[:2] for mm_level, vox_level in zip(params, vox_params_i)] |
| 276 | + assert np.array_equal(vox_values_i, mm_values / 2) |
| 277 | + |
| 278 | + vox_params_j = _mm2vox(str(img_file), 'j', config) |
| 279 | + vox_values_j = [level[2] for level in vox_params_j] |
| 280 | + assert np.array_equal(vox_values_j, mm_values / 3) |
| 281 | + |
| 282 | + vox_params_k = _mm2vox(str(img_file), 'k', config) |
| 283 | + vox_values_k = [level[2] for level in vox_params_k] |
| 284 | + assert np.array_equal(vox_values_k, mm_values / 4) |
0 commit comments