spectralbrain.apply_parcellation#

spectralbrain.apply_parcellation(vertices, faces, labels, *, ignore_labels=None)[source]#

Split a surface into sub-meshes according to a parcellation.

Given a cortical mesh and a per-vertex label array (e.g. from a Schaefer .annot), extracts one sub-mesh per parcel.

Parameters:
  • vertices (ndarray, shape (N, 3)) – Full mesh vertices.

  • faces (ndarray, shape (F, 3)) – Full mesh faces.

  • labels (ndarray, shape (N,)) – Per-vertex parcel labels.

  • ignore_labels (list of int, optional) – Labels to skip (e.g. [0] for the medial wall in Schaefer).

Returns:

dict of {int ((vertices, faces)}) – Mapping from label ID to the corresponding sub-mesh. Each sub-mesh has re-indexed faces starting from 0.

Return type:

dict[int, tuple[ndarray[tuple[Any, …], dtype[floating]], ndarray[tuple[Any, …], dtype[int64]]]]

Notes

This is the building block for the geometric connectome: apply a Schaefer-200 parcellation, compute spectral descriptors per parcel, and build a 200×200 similarity matrix.

Examples

>>> verts, faces = sb.io.load_freesurfer_surface("lh.white")
>>> labels, _, names = sb.io.load_freesurfer_annot(
...     "lh.Schaefer2018_200Parcels_7Networks_order.annot")
>>> parcels = sb.io.apply_parcellation(verts, faces, labels,
...                                     ignore_labels=[0])
>>> len(parcels)
100  # 100 left-hemisphere parcels
>>> parcels[1][0].shape  # vertices of parcel 1
(823, 3)