.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/06_manipulating_images/plot_compare_mean_image.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_06_manipulating_images_plot_compare_mean_image.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 13-14 Fetching 2 subject movie watching brain development fmri datasets. .. GENERATED FROM PYTHON SOURCE LINES 14-18 .. code-block:: default from nilearn import datasets dataset = datasets.fetch_development_fmri(n_subjects=2) .. GENERATED FROM PYTHON SOURCE LINES 19-20 Print basic information on the adhd subjects resting state datasets. .. GENERATED FROM PYTHON SOURCE LINES 20-24 .. code-block:: default print('Subject 1 resting state dataset at: %s' % dataset.func[0]) print('Subject 2 resting state dataset at: %s' % dataset.func[1]) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Subject 1 resting state dataset at: /home/nicolas/nilearn_data/development_fmri/development_fmri/sub-pixar123_task-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz Subject 2 resting state dataset at: /home/nicolas/nilearn_data/development_fmri/development_fmri/sub-pixar001_task-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz .. GENERATED FROM PYTHON SOURCE LINES 25-26 Comparing the means of the 2 movie watching datasets. .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: default from nilearn import plotting, image result_img = image.math_img("np.mean(img1, axis=-1) - np.mean(img2, axis=-1)", img1=dataset.func[0], img2=dataset.func[1]) plotting.plot_stat_map(result_img, title="Comparing means of 2 resting state 4D images.") plotting.show() .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_compare_mean_image_001.png :alt: plot compare mean image :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_compare_mean_image_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.128 seconds) **Estimated memory usage:** 765 MB .. _sphx_glr_download_auto_examples_06_manipulating_images_plot_compare_mean_image.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/nilearn/nilearn.github.io/main?filepath=examples/auto_examples/06_manipulating_images/plot_compare_mean_image.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_compare_mean_image.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_compare_mean_image.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_