In [ ]:
%matplotlib inline

Comparing the means of 2 images

The goal of this example is to illustrate the use of the function :func:nilearn.image.math_img with a list of images as input. We compare the means of 2 resting state 4D images. The mean of the images could have been computed with nilearn :func:nilearn.image.mean_img function.

Fetching 2 subject movie watching brain development fmri datasets.

In [ ]:
from nilearn import datasets
dataset = datasets.fetch_development_fmri(n_subjects=2)

Print basic information on the adhd subjects resting state datasets.

In [ ]:
print('Subject 1 resting state dataset at: %s' % dataset.func[0])
print('Subject 2 resting state dataset at: %s' % dataset.func[1])

Comparing the means of the 2 movie watching datasets.

In [ ]:
from nilearn import plotting, image

result_img = image.math_img("np.mean(img1, axis=-1) - np.mean(img2, axis=-1)",

                       title="Comparing means of 2 resting state 4D images.")