[Neuroimaging] flipping left-right side of images

Christophe Pallier christophe at pallier.org
Wed Jan 22 10:09:25 EST 2020

Dear all ,

I am trying to flip maks images which are in MNI space.
I have tried the  naive approach of flipping the data array in voxel
space, but the results is not satisfactory (the result is not
symmetrical to the original)

from numpy import flip

img = nib.load('mask.nii')
data = img.get_data()
nib.save(nib.Nifti1Image(np.flip(data, axis=0),  affine=img.affine), 'test.nii')

I also tried to hack the affine matrix, switching the sign of the
first element, and using nilearn.image.resample_img, to create a new
image, but with bad result.

Any suggestion?

More information about the Neuroimaging mailing list