How can I properly align glass brain plots in NILearn?

Hi. I’m attempting to plot nii images (from the BraTS dataset) using the plot_glass_brain function. However, the resultant image is all out of alignment. What can I do to fix this?

I’m thinking it could have something to do with those images not being in MNI space, so you may need to transform them. I’m not sure what the best way to transform the coordinates is but you could try this to see if it changes anything until a better suggesting comes along:

from nilearn import datasets, image
import nilearn.plotting as nip
img = image.load_img(‘path/to/your/file’)
mni = datasets.load_mni152_template()
img.affine = mni.affine.copy()

Hi @Eli

Indeed, this is most likely due to the images not being in MNI space. You can resample your input image to the MNI152 template like this:

from nilearn.image import resample_to_img, load_img
from nilearn.datasets import load_mni152_template

mni = load_mni152_template()
niimg = load_img(path/to/img)
resampled = resample_to_img(niimg, mni)

Hope this helps!