diff --git a/fsl/data/image.py b/fsl/data/image.py index d6f4180374f5f466bbce005d546fb62bcada7204..3cc6071ff72eb39da53a5ed8abcdf806ddd0dda6 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)