.. 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 :ref:`Go to the end ` 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 12-13 Fetching 2 subject movie watching brain development :term:`fMRI` datasets. .. GENERATED FROM PYTHON SOURCE LINES 13-18 .. code-block:: Python 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:: Python print(f"Subject 1 resting state dataset at: {dataset.func[0]}") print(f"Subject 2 resting state dataset at: {dataset.func[1]}") .. rst-class:: sphx-glr-script-out .. code-block:: none Subject 1 resting state dataset at: /home/himanshu/nilearn_data/development_fmri/development_fmri/sub-pixar123_task-pixar_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz Subject 2 resting state dataset at: /home/himanshu/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-38 .. code-block:: Python from nilearn import image, plotting 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 10.909 seconds) **Estimated memory usage:** 898 MB .. _sphx_glr_download_auto_examples_06_manipulating_images_plot_compare_mean_image.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/nilearn/nilearn/main?urlpath=lab/tree/notebooks/auto_examples/06_manipulating_images/plot_compare_mean_image.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_compare_mean_image.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_compare_mean_image.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_