|
24 | 24 | from nibabel.nifti1 import Nifti1Image
|
25 | 25 | from nibabel.nifti2 import Nifti2Image
|
26 | 26 | from nibabel.orientations import flip_axis, inv_ornt_aff
|
27 |
| -from nibabel.affines import AffineError, from_matvec, to_matvec, apply_affine |
| 27 | +from nibabel.affines import (AffineError, from_matvec, to_matvec, apply_affine, |
| 28 | + voxel_sizes) |
28 | 29 | from nibabel.eulerangles import euler2mat
|
29 | 30 |
|
30 | 31 | from numpy.testing import (assert_almost_equal,
|
|
41 | 42 |
|
42 | 43 | DATA_DIR = pjoin(dirname(__file__), 'data')
|
43 | 44 |
|
| 45 | +# 3D MINC work correctly with processing, but not 4D MINC |
| 46 | +from .test_imageclasses import MINC_3DS, MINC_4DS |
| 47 | + |
| 48 | +# Filenames of other images that should work correctly with processing |
| 49 | +OTHER_IMGS = ('anatomical.nii', 'functional.nii', |
| 50 | + 'example4d.nii.gz', 'example_nifti2.nii.gz', |
| 51 | + 'phantom_EPI_asc_CLEAR_2_1.PAR') |
| 52 | + |
| 53 | + |
44 | 54 | def test_sigma2fwhm():
|
45 | 55 | # Test from constant
|
46 | 56 | assert_almost_equal(sigma2fwhm(1), 2.3548200)
|
@@ -346,6 +356,25 @@ def test_smooth_image():
|
346 | 356 | Nifti2Image)
|
347 | 357 |
|
348 | 358 |
|
| 359 | +def test_spatial_axes_check(): |
| 360 | + for fname in MINC_3DS + OTHER_IMGS: |
| 361 | + img = nib.load(pjoin(DATA_DIR, fname)) |
| 362 | + s_img = smooth_image(img, 0) |
| 363 | + assert_array_equal(img.dataobj, s_img.dataobj) |
| 364 | + out = resample_from_to(img, img, mode='nearest') |
| 365 | + assert_almost_equal(img.dataobj, out.dataobj) |
| 366 | + if len(img.shape) > 3: |
| 367 | + continue |
| 368 | + # Resample to output does not raise an error |
| 369 | + out = resample_to_output(img, voxel_sizes(img.affine)) |
| 370 | + for fname in MINC_4DS: |
| 371 | + img = nib.load(pjoin(DATA_DIR, fname)) |
| 372 | + assert_raises(ValueError, smooth_image, img, 0) |
| 373 | + assert_raises(ValueError, resample_from_to, img, img, mode='nearest') |
| 374 | + assert_raises(ValueError, |
| 375 | + resample_to_output, img, voxel_sizes(img.affine)) |
| 376 | + |
| 377 | + |
349 | 378 | def assert_spm_resampling_close(from_img, our_resampled, spm_resampled):
|
350 | 379 | """ Assert our resampling is close to SPM's, allowing for edge effects
|
351 | 380 | """
|
|
0 commit comments