From 2d66509237432d9bb1e7380487dd053285935fb8 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Wed, 4 Oct 2017 15:30:24 +0100 Subject: [PATCH] Image.reample method allows data type to be specified --- fsl/data/image.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fsl/data/image.py b/fsl/data/image.py index d6f418037..3cc6071ff 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -1116,12 +1116,15 @@ class Image(Nifti): self.notify(topic='saveState') - def resample(self, shape, sliceobj=None, **kwargs): + def resample(self, shape, sliceobj=None, dtype=None, **kwargs): """Returns a copy of the data in this ``Image``, resampled to the specified ``shape``. :arg shape: Desired shape + :arg dtype: ``numpy`` data type of the resampled data. If ``None``, + the :meth:`dtype` of this ``Image`` is used. + :arg sliceobj: Slice into this ``Image``. If ``None``, the whole image is resampled, and it is assumed that it has the same number of dimensions as ``shape``. @@ -1133,14 +1136,14 @@ class Image(Nifti): interpolated copy of the data in this ``Image``. """ - if sliceobj is None: - sliceobj = slice(None) + if sliceobj is None: sliceobj = slice(None) + if dtype is None: dtype = self.dtype ndims = len(shape) data = self[sliceobj] if tuple(data.shape) != tuple(shape): - data = np.array(data, dtype=np.float, copy=False) + data = np.array(data, dtype=dtype, copy=False) zooms = [float(shape[i]) / data.shape[i] for i in range(ndims)] data = ndimage.zoom(data, zooms, **kwargs) -- GitLab