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

BF: Fix up adjust method

parent 8393c2bd
No related branches found
No related tags found
No related merge requests found
......@@ -864,22 +864,26 @@ class Nifti(notifier.Notifier, meta.Meta):
raise ValueError('Exactly one of pixdim or '
'shape must be specified')
if shape is not None: ndim = len(shape)
else: ndim = len(pixdim)
# We only allow adjustment of
# the spatial dimensions
if ndim != 3:
raise ValueError('Three dimensions must be specified')
oldShape = np.array(self.shape[ :ndim])
oldPixdim = np.array(self.pixdim[:ndim])
newShape = shape
newPixdim = pixdim
# if pixdims were specified,
# convert them into a shape
# convert them into a shape,
# and vice versa
if newPixdim is not None:
npixdim = len(newPixdim)
newPixdim = np.array(newPixdim)
oldShape = np.array(self.shape[ :npixdim])
oldPixdim = np.array(self.pixdim[:npixdim])
newShape = oldShape * (oldPixdim / newPixdim)
# We only allow adjustment of
# the spatial dimensions
if len(newShape) != 3:
raise ValueError('Three dimensions must be specified')
newShape = oldShape * (oldPixdim / newPixdim)
else:
newPixdim = oldPixdim * (oldShape / newShape)
# Rescale the voxel-to-world affine
xform = affine.rescale(oldShape, newShape, origin)
......
......@@ -588,7 +588,7 @@ def rmsdev(T1, T2, R=None, xc=None):
def rescale(oldShape, newShape, origin=None):
"""Calculates an affine matrix to use for resampling.
This function generates an affine transformation matreix that can be used
This function generates an affine transformation matrix that can be used
to resample an N-D array from ``oldShape`` to ``newShape`` using, for
example, ``scipy.ndimage.affine_transform``.
......
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