In [ ]:
%matplotlib inline
In [ ]:
from nilearn import datasets
print('Datasets are stored in: %r' % datasets.get_data_dirs())
Let's now retrieve a motor contrast from a localizer experiment
In [ ]:
tmap_filenames = datasets.fetch_localizer_button_task()['tmaps']
print(tmap_filenames)
tmap_filenames is a list of filenames. We need to take the first one
In [ ]:
tmap_filename = tmap_filenames[0]
In [ ]:
from nilearn import plotting
plotting.plot_stat_map(tmap_filename)
Visualizing works better with a threshold
In [ ]:
plotting.plot_stat_map(tmap_filename, threshold=3)
In [ ]:
rsn = datasets.fetch_atlas_smith_2009()['rsn10']
print(rsn)
It is a 4D nifti file. We load it into the memory to print its shape.
In [ ]:
from nilearn import image
print(image.load_img(rsn).shape)
We can retrieve the first volume (note that Python indexing starts at 0):
In [ ]:
first_rsn = image.index_img(rsn, 0)
print(first_rsn.shape)
first_rsn is a 3D image.
We can then plot it
In [ ]:
plotting.plot_stat_map(first_rsn)
In [ ]:
for img in image.iter_img(rsn):
# img is now an in-memory 3D img
plotting.plot_stat_map(img, threshold=3, display_mode="z", cut_coords=1,
colorbar=False)
plotting.show is useful to force the display of figures when running outside IPython
In [ ]:
plotting.show()
|
To recap, neuroimaging images (niimgs as we call them) come in different flavors:
More details about the input formats in nilearn for 3D and 4D images is
given in the documentation section: loading_data.
Functions accept either 3D or 4D images, and we need to use on the one
hand :func:nilearn.image.index_img or :func:nilearn.image.iter_img
to break down 4D images into 3D images, and on the other hand
:func:nilearn.image.concat_imgs to group a list of 3D images into a 4D
image.