I enjoy using Nilearn’s plotting features. However, if I am not misunderstood, nilearn appears to resample images before plotting.
My current data contains only 7 slices in the ‘z’ direction. I would like to plot each slice on an array using nilearn. However, I cannot figure out how to do so.
If anybody could help me or suggest alternative packages which could achieve this , that would be much appreciated.
Many thanks,
Joe
p.s. (I realise that I could achieve this manually using fsleyes but would like to script this)
p.p.s (I also realise that FSLeyes has a command line interface and hence could be scripted, however, I find it difficult to adjust the contrasts etc etc)
hello, thanks for your interest. your data has 7 slices but is it a brain image
with an affine? and do you want to plot it against an anatomical image as background?
if yes, you could resample the background image (e.g.
nilearn.datasets.load_mni152_template() ) to your image using
nilearn.image.resample_to_img, then pass the resampled background as bg_img
kwarg to nilearn plotting functions. then no resampling will take place in the
plotting functions because your image and the passed background will have the
same affine and shape.
if no, why not simply use matplotlib.pyplot.imshow or something similar?
example plots of an image which has only 8 vertical slices:
Hi, the affine of the image is not diagonal. I think in order to plot it nilearn rotates it so that the dimensions of the image are aligned with x, y, z axes. apparently when you cut your image in this directions the top slices have the shape you show , which seem to be cut. if you fool nilearn into ignoring the affine the slices don’t seem cut anymore:
I think this may be what I need. Could you please explain/ post the code that you used to do this?
The field of view for the stat map is indeed much larger. It was acquired immediately following the T1w image in the same space, and so setting the T1w image as the bg_image should work via resampling, no?
but it is a hack and you lose the affine; it gives you the same thing as you would get by plotting each slice eg with pyplot.imshow. the image looks weird when I resample it to the anatomical image.