Skip to content

Instantly share code, notes, and snippets.

@arokem
Created December 1, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arokem/0aab282a7287245a7e78 to your computer and use it in GitHub Desktop.
Save arokem/0aab282a7287245a7e78 to your computer and use it in GitHub Desktop.
from dipy.align.imaffine import AffineMap
def resample_volume(moving, static):
"""
Resample a nifti image into the space of another nifti image
Parameters
----------
moving : Nifti1Image
The 'source' image.
static : Nifti1Image
The 'target' image.
Returns
-------
resampled_img : Nifti1Image
The source data in the target space, with the target affine
"""
affine_map = AffineMap(np.eye(4),
static.shape, static.affine,
moving.shape, moving.affine)
resampled = affine_map.transform(moving.get_data())
return nib.Nifti1Image(resampled, static.get_affine())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment