[Neuroimaging] Aligning low and high resolution images in voxel space

Matthew Brett matthew.brett at gmail.com
Tue Dec 1 15:01:39 EST 2015


Hi,

On Tue, Dec 1, 2015 at 9:55 AM, Greg Kiar <gkiar07 at gmail.com> wrote:
> Hi,
>
> I'm working with various parcellations of the brain which have been defined
> at a 3mm resolution, though my data exists in a 1mm space (the MNI152
> space). When opening these images with a nifti viewer it is fine as the
> affine transform maps them properly to scale. However, when I'm working with
> data in python I would like my labels defined at 3mm to be in the MNI152
> space (that they also overlap in voxel space, as well). I would like to
> write a script that "ingests" a low resolution (3mm) atlas into the 1mm
> MNI152 space, and nearest-neighbor interpolates values not defined, if you
> will. Do you know how I can easily do this?

Maybe something like:

vox2mm3 = img_3mm.affine
vox2mm1 = img_1mm.affine
vox1to3 = np.linalg.inv(vox2mm3).dot(vox2mm1)
mat, vec = nibabel.affines.to_matvec(vox1to3)
out = scipy.ndimage.affine_transform(img_3mm.get_data(), mat, vec, order=0)
out_img = nibabel.Nifti1Image(out, img_1mm.affine, img_1mm.header)
nibabel.save(out_img, 'my_resampled_regions.nii')

Cheers,

Matthew


More information about the Neuroimaging mailing list