diff --git a/fsl/data/image.py b/fsl/data/image.py index dca8d84c17e09ac5c8212482435e61358e38d9a1..0f8a9995df0acf2170cd9e130653150ee55491e7 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -1132,8 +1132,14 @@ class Image(Nifti): All other arguments are passed through to the ``scipy.ndimage.zoom`` function. - :returns: A ``numpy`` array of shape ``shape``, containing an - interpolated copy of the data in this ``Image``. + :returns: A tuple containing: + + - A ``numpy`` array of shape ``shape``, containing an + interpolated copy of the data in this ``Image``. + + - A ``numpy`` array of shape ``(4, 4``), containing the + adjusted voxel-to-world transformation for the resampled + data. """ if sliceobj is None: sliceobj = slice(None) @@ -1144,10 +1150,20 @@ class Image(Nifti): data = np.array(data, dtype=dtype, copy=False) if tuple(data.shape) != tuple(shape): - zooms = [float(shape[i]) / data.shape[i] for i in range(ndims)] - data = ndimage.zoom(data, zooms, **kwargs) - return data + oldShape = data.shape + zooms = [float(shape[i]) / data.shape[i] for i in range(ndims)] + data = ndimage.zoom(data, zooms, **kwargs) + + newShape = data.shape + scale = [os / float(ns) for os, ns in zip(oldShape, newShape)] + offset = [(s - 1) / 2.0 for s in scale] + scale = transform.scaleOffsetXform(scale, offset) + xform = transform.concat(self.voxToWorldMat, scale) + else: + xform = self.voxToWorldMat + + return data, xform def __getitem__(self, sliceobj):