From a69bd9e461143e9e535d540ffd4ade206e5fd035 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Wed, 28 Nov 2018 11:52:32 +0000 Subject: [PATCH] RF: Image.resample supports data with more than 3 dimensions. --- fsl/data/image.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fsl/data/image.py b/fsl/data/image.py index a1e695b59..24e129c8b 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -1173,7 +1173,7 @@ class Image(Nifti): order=1, smooth=True): """Returns a copy of the data in this ``Image``, resampled to the - specified ``shape``. + specified ``newShape``. :arg newShape: Desired shape. May containg floating point values, in which case the resampled image will have shape @@ -1182,7 +1182,7 @@ class Image(Nifti): :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``. A + same number of dimensions as ``newShape``. A :exc:`ValueError` is raised if this is not the case. :arg dtype: ``numpy`` data type of the resampled data. If ``None``, @@ -1201,12 +1201,12 @@ class Image(Nifti): :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 ``newShape``, 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. + adjusted voxel-to-world transformation for the spatial + dimensions of the resampled data. """ if sliceobj is None: sliceobj = slice(None) @@ -1225,7 +1225,7 @@ class Image(Nifti): ratio = oldShape / newShape newShape = np.array(np.round(newShape), dtype=np.int) - scale = transform.scaleOffsetXform(ratio, 0) + scale = np.diag(ratio) # If interpolating and smoothing, we apply a # gaussian filter along axes with a resampling @@ -1242,7 +1242,7 @@ class Image(Nifti): data = ndimage.gaussian_filter(data, sigma) data = ndimage.affine_transform(data, - scale[:3, :3], + scale, output_shape=newShape, order=order) @@ -1250,6 +1250,7 @@ class Image(Nifti): # puts the resampled image into the # same world coordinate system as this # image. + scale = transform.scaleOffsetXform(ratio[:3], 0) xform = transform.concat(self.voxToWorldMat, scale) else: xform = self.voxToWorldMat -- GitLab