diff --git a/fsl/data/image.py b/fsl/data/image.py index 0f8a9995df0acf2170cd9e130653150ee55491e7..c85d3ab612a651c165c08e81ae696d6952b0bd5b 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -1137,7 +1137,7 @@ class Image(Nifti): - 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 + - A ``numpy`` array of shape ``(4, 4)``, containing the adjusted voxel-to-world transformation for the resampled data. """ @@ -1152,13 +1152,21 @@ class Image(Nifti): if tuple(data.shape) != tuple(shape): oldShape = data.shape - zooms = [float(shape[i]) / data.shape[i] for i in range(ndims)] - data = ndimage.zoom(data, zooms, **kwargs) - + zooms = [float(data.shape[i]) / shape[i] for i in range(ndims)] + zooms = np.diag(zooms) + + data = ndimage.affine_transform(data, + zooms, + output_shape=shape, + **kwargs) + + # Construct an affine transform which + # puts the resampled image into the + # same world coordinate system as this + # image. 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) + scale = transform.scaleOffsetXform(scale, 0) xform = transform.concat(self.voxToWorldMat, scale) else: xform = self.voxToWorldMat