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()
# Contrast map of motor task
localizer_tmap_filename = localizer_dataset.tmap
# Subject specific anatomical image
localizer_anat_filename = localizer_dataset.anat
[fetch_localizer_button_task] Dataset created in
/home/runner/nilearn_data/brainomics_localizer
[fetch_localizer_button_task] Downloading data from
https://osf.io/hwbm2/download ...
[fetch_localizer_button_task]  ...done. (17 seconds, 0 min)

[fetch_localizer_button_task] Downloading data from
https://osf.io/download/5d27ddc91c5b4a001b9ef9d0/ ...
[fetch_localizer_button_task]  ...done. (3 seconds, 0 min)

[fetch_localizer_button_task] Downloading data from
https://osf.io/download/5d27d29145253a001c3e284f/ ...
[fetch_localizer_button_task]  ...done. (17 seconds, 0 min)

[fetch_localizer_button_task] Downloading data from
https://osf.io/download/5d275ede1c5b4a001aa00c26/ ...
[fetch_localizer_button_task] Downloaded 737280 of 13951266 bytes (5.3%%,
18.5s remaining)
[fetch_localizer_button_task] Downloaded 1753088 of 13951266 bytes (12.6%%,
14.2s remaining)
[fetch_localizer_button_task] Downloaded 2768896 of 13951266 bytes (19.8%%,
12.4s remaining)
[fetch_localizer_button_task] Downloaded 3784704 of 13951266 bytes (27.1%%,
10.9s remaining)
[fetch_localizer_button_task] Downloaded 4784128 of 13951266 bytes (34.3%%,
9.7s remaining)
[fetch_localizer_button_task] Downloaded 5799936 of 13951266 bytes (41.6%%,
8.5s remaining)
[fetch_localizer_button_task] Downloaded 6832128 of 13951266 bytes (49.0%%,
7.4s remaining)
[fetch_localizer_button_task] Downloaded 7733248 of 13951266 bytes (55.4%%,
6.5s remaining)
[fetch_localizer_button_task] Downloaded 8814592 of 13951266 bytes (63.2%%,
5.3s remaining)
[fetch_localizer_button_task] Downloaded 9846784 of 13951266 bytes (70.6%%,
4.2s remaining)
[fetch_localizer_button_task] Downloaded 10911744 of 13951266 bytes (78.2%%,
3.1s remaining)
[fetch_localizer_button_task] Downloaded 11943936 of 13951266 bytes (85.6%%,
2.0s remaining)
[fetch_localizer_button_task] Downloaded 13025280 of 13951266 bytes (93.4%%,
0.9s remaining)
[fetch_localizer_button_task]  ...done. (23 seconds, 0 min)

[fetch_localizer_button_task] Downloading data from
https://osf.io/download/5d27037f45253a001c3d4563/ ...
[fetch_localizer_button_task]  ...done. (1 seconds, 0 min)

[fetch_localizer_button_task] Downloading data from
https://osf.io/download/5d7b8948fcbf44001c44e695/ ...
[fetch_localizer_button_task]  ...done. (4 seconds, 0 min)

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

from nilearn.plotting import plot_stat_map, show

cut_coords = (36, -27, 66)

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

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

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

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

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

Plotting with more decrease in contrast with dim=1

plot_stat_map(
    localizer_tmap_filename,
    bg_img=localizer_anat_filename,
    cut_coords=cut_coords,
    threshold=3,
    title="dim=1",
    dim=1,
)

show()
plot dim plotting

Total running time of the script: (1 minutes 12.676 seconds)

Estimated memory usage: 100 MB

Gallery generated by Sphinx-Gallery