Loading and plotting of a cortical surface atlas

Warning

This is an adaption of Loading and plotting of a cortical surface atlas to use make it work with the new experimental surface API.

The Destrieux parcellation (Destrieux et al.[1]) in fsaverage5 space as distributed with Freesurfer is used as the chosen atlas.

The nilearn.plotting.plot_surf_roi function is used to plot the parcellation on the pial surface.

See Plotting brain images for more details.

Data fetcher

# Retrieve destrieux parcellation in fsaverage5 space from nilearn
from nilearn.experimental.surface import (
    fetch_destrieux,
    load_fsaverage,
    load_fsaverage_data,
)

destrieux_atlas, labels = fetch_destrieux(mesh_type="pial")

# Retrieve fsaverage5 surface dataset for the plotting background.
# It contains the surface template as pial and inflated version.
fsaverage_meshes = load_fsaverage()

# The fsaverage meshes contains the FileMesh objects:
print(
    "Fsaverage5 pial surface of left hemisphere is: "
    f"{fsaverage_meshes['pial'].parts['left']}"
)
print(
    "Fsaverage5 inflated surface of left hemisphere is: "
    f"{fsaverage_meshes['inflated'].parts['left']}"
)

# The fsaverage data contains file names pointing to the file locations
# The sulcal depth maps will be is used for shading.
fsaverage_sulcal = load_fsaverage_data(data_type="sulcal")
print(f"Fsaverage5 sulcal depth map: {fsaverage_sulcal}")
[get_dataset_dir] Dataset found in /home/runner/work/nilearn/nilearn/nilearn_data/destrieux_surface
Fsaverage5 pial surface of left hemisphere is: <FileMesh with 10242 vertices>
Fsaverage5 inflated surface of left hemisphere is: <FileMesh with 10242 vertices>
Fsaverage5 sulcal depth map: <SurfaceImage (20484,)>

Visualization

# Display Destrieux :term:`parcellation` on fsaverage5 sulcal surface
from nilearn.experimental import plotting
from nilearn.plotting import show

plotting.plot_surf_roi(
    roi_map=destrieux_atlas,
    hemi="left",
    view="lateral",
    bg_map=fsaverage_sulcal,
    bg_on_data=True,
    darkness=0.5,
    title="Destrieux parcellation on sulcal surface",
)
Destrieux parcellation on sulcal surface
<Figure size 400x500 with 1 Axes>

Display Destrieux parcellation on inflated fsaverage5 surface with different views

for view in ["lateral", "posterior", "ventral"]:
    plotting.plot_surf_roi(
        surf_mesh=fsaverage_meshes["inflated"],
        roi_map=destrieux_atlas,
        hemi="left",
        view=view,
        bg_map=fsaverage_sulcal,
        bg_on_data=True,
        darkness=0.5,
        title=f"Destrieux parcellation on inflated surface\n{view} view",
    )

show()
  • Destrieux parcellation on inflated surface lateral view
  • Destrieux parcellation on inflated surface posterior view
  • Destrieux parcellation on inflated surface ventral view

Display Destrieux parcellation with custom view: explicitly set angle

elev, azim = 210.0, 90.0  # appropriate for visualizing, e.g., the OTS
plotting.plot_surf_roi(
    surf_mesh=fsaverage_meshes["inflated"],
    roi_map=destrieux_atlas,
    hemi="left",
    view=(elev, azim),
    bg_map=fsaverage_sulcal,
    bg_on_data=True,
    darkness=0.5,
    title="Arbitrary view of Destrieux parcellation",
)
Arbitrary view of Destrieux parcellation
<Figure size 400x500 with 1 Axes>

Display connectome from surface parcellation

The following code extracts 3D coordinates of surface parcels (also known as labels in the Freesurfer naming convention). To do so we get the pial surface of fsaverage subject, get the vertices contained in each parcel and compute the mean location to obtain the coordinates.

import numpy as np

from nilearn import surface
from nilearn.plotting import plot_connectome, view_connectome

coordinates = []
for hemi in ["left", "right"]:
    vert = destrieux_atlas.data.parts[hemi]
    rr, _ = surface.load_surf_mesh(fsaverage_meshes["pial"].parts[hemi])
    coordinates.extend(
        np.mean(rr[vert == k], axis=0)
        for k, label in enumerate(labels)
        if "Unknown" not in str(label)
    )
coordinates = np.array(coordinates)  # 3D coordinates of parcels

# We now make a synthetic connectivity matrix that connects labels
# between left and right hemispheres.
n_parcels = len(coordinates)
corr = np.zeros((n_parcels, n_parcels))
n_parcels_hemi = n_parcels // 2
corr[np.arange(n_parcels_hemi), np.arange(n_parcels_hemi) + n_parcels_hemi] = 1
corr = corr + corr.T

plot_connectome(
    corr, coordinates, edge_threshold="90%", title="Connectome Destrieux atlas"
)
show()
plot surf atlas experimental

3D visualization in a web browser

An alternative to nilearn.plotting.plot_surf_roi is to use nilearn.plotting.view_surf for more interactive visualizations in a web browser. See 3D Plots of statistical maps or atlases on the cortical surface for more details.

view = plotting.view_surf(
    surf_mesh=fsaverage_meshes["inflated"],
    surf_map=destrieux_atlas,
    cmap="gist_ncar",
    symmetric_cmap=False,
    colorbar=False,
)
# In a Jupyter notebook, if ``view`` is the output of a cell,
# it will be displayed below the cell

view