8.1.4. A introduction tutorial to fMRI decoding

Here is a simple tutorial on decoding with nilearn. It reproduces the Haxby 2001 study on a face vs cat discrimination task in a mask of the ventral stream.

This tutorial is meant as an introduction to the various steps of a decoding analysis.

It is not a minimalistic example, as it strives to be didactic. It is not meant to be copied to analyze new data: many of the steps are unecessary.

8.1.4.1. Retrieve and load the fMRI data from the Haxby study

8.1.4.1.1. First download the data

The nilearn.datasets.fetch_haxby function will download the Haxby dataset if not present on the disk, in the nilearn data directory. It can take a while to download about 310 Mo of data from the Internet.

from nilearn import datasets
# By default 2nd subject will be fetched
haxby_dataset = datasets.fetch_haxby()
# 'func' is a list of filenames: one for each subject
fmri_filename = haxby_dataset.func[0]

# print basic information on the dataset
print('First subject functional nifti images (4D) are at: %s' %
      fmri_filename)  # 4D data

Out:

First subject functional nifti images (4D) are at: /home/emdupre/nilearn_data/haxby2001/subj2/bold.nii.gz

8.1.4.1.2. Visualizing the fmri volume

One way to visualize a fmri volume is using nilearn.plotting.plot_epi. We will visualize the previously fecthed fmri data from Haxby dataset.

Because fmri data is 4D (it consists of many 3D EPI images), we cannot plot it directly using nilearn.plotting.plot_epi (which accepts just 3D input). Here we are using nilearn.image.mean_img to extract a single 3D EPI image from the fmri data.

from nilearn import plotting
from nilearn.image import mean_img
plotting.view_img(mean_img(fmri_filename), threshold=None)