Controlling the contrast of the background when plotting#

The dim argument controls the contrast of the background.

dim modifies the contrast of this image: dim=0 leaves the image unchanged, negative values of dim enhance it, and positive values decrease it (dim the background).

This dim argument may also be useful for the plot_roi function used to display ROIs on top of a background image.

Retrieve the data: the localizer dataset with contrast maps#

from nilearn import datasets

localizer_dataset = datasets.fetch_localizer_button_task(legacy_format=False)
# Contrast map of motor task
localizer_tmap_filename = localizer_dataset.tmap
# Subject specific anatomical image
localizer_anat_filename = localizer_dataset.anat
Dataset created in /home/remi/nilearn_data/brainomics_localizer

Downloading data from https://osf.io/hwbm2/download ...

Downloaded 778240 of 1508563 bytes (51.6%,    0.9s remaining) ...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5d27ddc91c5b4a001b9ef9d0/ ...
 ...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5d27d29145253a001c3e284f/ ...
 ...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5d275ede1c5b4a001aa00c26/ ...

Downloaded 2990080 of 13951266 bytes (21.4%,    3.7s remaining)
Downloaded 5693440 of 13951266 bytes (40.8%,    2.9s remaining)
Downloaded 8822784 of 13951266 bytes (63.2%,    1.8s remaining)
Downloaded 11821056 of 13951266 bytes (84.7%,    0.7s remaining) ...done. (6 seconds, 0 min)
Downloading data from https://osf.io/download/5d27037f45253a001c3d4563/ ...
 ...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5d7b8948fcbf44001c44e695/ ...
 ...done. (1 seconds, 0 min)

Plotting with enhancement of background image with dim=-.5#

from nilearn import plotting

plotting.plot_stat_map(
    localizer_tmap_filename,
    bg_img=localizer_anat_filename,
    cut_coords=(36, -27, 66),
    threshold=3,
    title="dim=-.5",
    dim=-0.5,
)
plot dim plotting
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7fd1f246bd90>

Plotting with no change of contrast in background image with dim=0#

plotting.plot_stat_map(
    localizer_tmap_filename,
    bg_img=localizer_anat_filename,
    cut_coords=(36, -27, 66),
    threshold=3,
    title="dim=0",
    dim=0,
)
plot dim plotting
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7fd1e33a2510>

Plotting with decrease of contrast in background image with dim=.5#

plotting.plot_stat_map(
    localizer_tmap_filename,
    bg_img=localizer_anat_filename,
    cut_coords=(36, -27, 66),
    threshold=3,
    title="dim=.5",
    dim=0.5,
)
plot dim plotting
<nilearn.plotting.displays._slicers.OrthoSlicer object at 0x7fd1f26a5a50>

Plotting with more decrease in contrast with dim=1#

plotting.plot_stat_map(
    localizer_tmap_filename,
    bg_img=localizer_anat_filename,
    cut_coords=(36, -27, 66),
    threshold=3,
    title="dim=1",
    dim=1,
)

plotting.show()
plot dim plotting

Total running time of the script: (0 minutes 23.722 seconds)

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery