Skip to content
Snippets Groups Projects
Commit cadec241 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Image.resample also returns xform

parent 43592412
No related branches found
No related tags found
No related merge requests found
...@@ -1132,8 +1132,14 @@ class Image(Nifti): ...@@ -1132,8 +1132,14 @@ class Image(Nifti):
All other arguments are passed through to the ``scipy.ndimage.zoom`` All other arguments are passed through to the ``scipy.ndimage.zoom``
function. function.
:returns: A ``numpy`` array of shape ``shape``, containing an :returns: A tuple containing:
interpolated copy of the data in this ``Image``.
- 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) if sliceobj is None: sliceobj = slice(None)
...@@ -1144,10 +1150,20 @@ class Image(Nifti): ...@@ -1144,10 +1150,20 @@ class Image(Nifti):
data = np.array(data, dtype=dtype, copy=False) data = np.array(data, dtype=dtype, copy=False)
if tuple(data.shape) != tuple(shape): 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): def __getitem__(self, sliceobj):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment