Skip to content
Snippets Groups Projects
Commit 1c090d38 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Unit test for resample method

parent 2eb4e3bf
No related branches found
No related tags found
No related merge requests found
...@@ -1000,3 +1000,36 @@ def _test_Image_save(imgtype): ...@@ -1000,3 +1000,36 @@ def _test_Image_save(imgtype):
finally: finally:
shutil.rmtree(testdir) 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment