.. 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_extract_rois_statistical_maps.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_extract_rois_statistical_maps.py: Region Extraction using a t-statistical map (3D) ================================================ This example shows how to extract regions or separate the regions from a statistical map. We use localizer t-statistic maps from :func:`nilearn.datasets.fetch_neurovault_auditory_computation_task` as an input image. The idea is to threshold an image to get foreground objects using a function :func:`nilearn.image.threshold_img` and extract objects using a function :func:`nilearn.regions.connected_regions`. .. GENERATED FROM PYTHON SOURCE LINES 19-21 Fetching t-statistic image of localizer contrasts by loading from datasets utilities .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python from nilearn import datasets localizer = datasets.fetch_neurovault_auditory_computation_task() tmap_filename = localizer.images[0] .. GENERATED FROM PYTHON SOURCE LINES 27-28 Threshold the t-statistic image by importing threshold function .. GENERATED FROM PYTHON SOURCE LINES 28-41 .. code-block:: Python from nilearn.image import threshold_img # Two types of strategies can be used from this threshold function # Type 1: strategy used will be based on scoreatpercentile threshold_percentile_img = threshold_img( tmap_filename, threshold="97%", copy=False ) # Type 2: threshold strategy used will be based on image intensity # Here, threshold value should be within the limits i.e. less than max value. threshold_value_img = threshold_img(tmap_filename, threshold=3.0, copy=False) .. GENERATED FROM PYTHON SOURCE LINES 42-44 Visualization Showing thresholding results by importing plotting modules and its utilities .. GENERATED FROM PYTHON SOURCE LINES 44-64 .. code-block:: Python from nilearn import plotting # Showing percentile threshold image plotting.plot_stat_map( threshold_percentile_img, display_mode="z", cut_coords=5, title="Threshold image with string percentile", colorbar=False, ) # Showing intensity threshold image plotting.plot_stat_map( threshold_value_img, display_mode="z", cut_coords=5, title="Threshold image with intensity value", colorbar=False, ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_001.png :alt: plot extract rois statistical maps :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_002.png :alt: plot extract rois statistical maps :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 65-66 Extracting the regions by importing connected regions function .. GENERATED FROM PYTHON SOURCE LINES 66-76 .. code-block:: Python from nilearn.regions import connected_regions regions_percentile_img, index = connected_regions( threshold_percentile_img, min_region_size=1500 ) regions_value_img, index = connected_regions( threshold_value_img, min_region_size=1500 ) .. GENERATED FROM PYTHON SOURCE LINES 77-78 Visualizing region extraction results .. GENERATED FROM PYTHON SOURCE LINES 78-93 .. code-block:: Python images = [regions_percentile_img, regions_value_img] for image, strategy in zip(images, ["percentile", "image intensity"]): title = ( f"ROIs using {strategy} thresholding. " "Each ROI in same color is an extracted region" ) plotting.plot_prob_atlas( image, bg_img=tmap_filename, view_type="contours", display_mode="z", cut_coords=5, title=title, ) plotting.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_003.png :alt: plot extract rois statistical maps :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_004.png :alt: plot extract rois statistical maps :srcset: /auto_examples/06_manipulating_images/images/sphx_glr_plot_extract_rois_statistical_maps_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.950 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_auto_examples_06_manipulating_images_plot_extract_rois_statistical_maps.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/0.10.4?urlpath=lab/tree/notebooks/auto_examples/06_manipulating_images/plot_extract_rois_statistical_maps.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_extract_rois_statistical_maps.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_extract_rois_statistical_maps.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_