.. 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_negate_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_negate_image.py: Negating an image with math_img =============================== The goal of this example is to illustrate the use of the function :func:`nilearn.image.math_img` on T-maps. We compute a negative image by multiplying its voxel values with -1. .. GENERATED FROM PYTHON SOURCE LINES 11-13 .. code-block:: Python from nilearn import datasets, image, plotting .. GENERATED FROM PYTHON SOURCE LINES 14-15 Retrieve the data: a motor :term:`contrast` map. .. GENERATED FROM PYTHON SOURCE LINES 15-18 .. code-block:: Python stat_img = datasets.load_sample_motor_activation_image() .. GENERATED FROM PYTHON SOURCE LINES 19-20 Multiply voxel values by -1. .. GENERATED FROM PYTHON SOURCE LINES 20-33 .. code-block:: Python negative_stat_img = image.math_img("-img", img=stat_img) plotting.plot_stat_map( stat_img, cut_coords=(36, -27, 66), threshold=3, title="t-map", vmax=9 ) plotting.plot_stat_map( negative_stat_img, cut_coords=(36, -27, 66), threshold=3, title="Negative t-map", vmax=9, ) plotting.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_negate_image_001.png :alt: plot negate image :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_negate_image_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_negate_image_002.png :alt: plot negate image :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_negate_image_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 14.285 seconds) **Estimated memory usage:** 160 MB .. _sphx_glr_download_auto_examples_06_manipulating_images_plot_negate_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_negate_image.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_negate_image.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_negate_image.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_