From 1c090d38b0b868a68144403eae1179c92de2f5cc Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Fri, 22 Sep 2017 11:16:32 +0100 Subject: [PATCH] Unit test for resample method --- tests/test_image.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_image.py b/tests/test_image.py index 5dc7aee98..2f005f04c 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -1000,3 +1000,36 @@ def _test_Image_save(imgtype): finally: shutil.rmtree(testdir) + + +def test_image_resample(seed): + + with testdir() as td: + + fname = op.join(td, 'test.nii') + + # Random base image shapes + for i in range(50): + + shape = np.random.randint(5, 100, 3) + make_random_image(fname, shape) + img = fslimage.Image(fname) + + # resampling to the same shape should be a no-op + assert np.all(img.resample(shape) == img[:]) + + # Random resampled image shapes + for i in range(10): + + rshape = np.random.randint(5, 100, 3) + resampled = img.resample(rshape) + + assert tuple(resampled.shape) == tuple(rshape) + + # Test a 4D image + make_random_image(fname, (10, 10, 10, 10)) + img = fslimage.Image(fname) + slc = (slice(None), slice(None), slice(None), 3) + + assert np.all(img.resample(img.shape[:3], slc) == img[..., 3]) + assert tuple(img.resample((15, 15, 15), slc).shape) == (15, 15, 15) -- GitLab