Skip to content

[ENH] Add adjacency for cortical and volume labels - #14226

Merged
larsoner merged 13 commits into
mne-tools:mainfrom
raphbrd:label-adj
Aug 27, 2026
Merged

[ENH] Add adjacency for cortical and volume labels#14226
larsoner merged 13 commits into
mne-tools:mainfrom
raphbrd:label-adj

Conversation

@raphbrd

@raphbrd raphbrd commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

PR description

Fixes #8646

Add two functions in the public API to determine whether labels are adjacent in source spaces:

  • mne.label_adjacency(labels, src) for surface spaces.
  • mne.volume_label_adjacency(src, subject, subjects_dir, aseg="auto", labels=None) for volumetric spaces.

The typical inputs are any surface parcels and segmentation files from the FreeSurfer recon process (e.g., aparc.a2009s+aseg.mgz)

Additional information

Adjacency between labels is defined as having at least one adjacent voxel, based on the source-space adjacency computed using the existing mne.source_estimate.spatial_src_adjacency function.

For the volumetric case, there is currently no dedicated label object. The current workaround is to use a list of surface labels with hemi='lh' by convention. If that's useful, we could add a VolLabel object in the future.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one tiny efficiency nitpick, otherwise LGTM! Let me know when you push and I'll mark for merge-when-green

Comment thread doc/changes/dev/14226.newfeature.rst Outdated
Comment thread mne/label.py Outdated
@larsoner
larsoner enabled auto-merge (squash) August 26, 2026 14:38
@larsoner

Copy link
Copy Markdown
Member
/home/circleci/project/doc/[towncrier-fragments]:194: WARNING: py:func reference target not found: mne.label_adjacency [ref.func]
/home/circleci/project/doc/[towncrier-fragments]:194: WARNING: py:func reference target not found: mne.volume_label_adjacency [ref.func]

@larsoner

Copy link
Copy Markdown
Member

(I'll push a fix)

@larsoner
larsoner merged commit f06fb38 into mne-tools:main Aug 27, 2026
31 checks passed
@welcome

welcome Bot commented Aug 27, 2026

Copy link
Copy Markdown

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@wmvanvliet

Copy link
Copy Markdown
Contributor

Thanks @raphbrd!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: find_labels_adjacency() function for cortical labels

3 participants