Intracranial Electrode Location and Analysis in MNE-Python

Alexander Rockhill, Eric Larson, Brittany Stedelin, Alessandra Mantovani, Ahmed M. Raslan, Alexandre Gramfort, Nicole C. SwannJ. Open Source Softw 2022 · DOI · DBLP

Abstract

Accurate localization of intracranial electrodes (sEEG and ECoG) is fundamental to interpreting neural activity in clinical and research settings. Historically, this process has relied on fragmented, often poorly maintained standalone software. This paper introduces a comprehensive, open-source pipeline integrated directly into the MNE-Python ecosystem. By combining automated image alignment, a dedicated interactive graphical user interface (GUI), and advanced non-linear warping techniques, the tool provides a streamlined, robust, and efficient workflow for researchers.

Introduction

In intracranial electrophysiology (iEEG), electrodes are implanted directly into or onto the brain to record neural signals with exceptional spatial and temporal resolution. To analyze these signals effectively, researchers must precisely determine the anatomical location of each electrode contact relative to the patient's brain. This typically requires aligning preoperative magnetic resonance imaging (MRI) for anatomical detail with postoperative computed tomography (CT) scans where electrodes appear as high-intensity markers.

The traditional workflow is often cumbersome, requiring multiple software packages, manual identification of dozens of contacts, and complex mapping to standard brain templates for group-level analysis. Many existing tools are written in MATLAB and suffer from installation difficulties or lack of long-term support. MNE-Python addresses these challenges by providing a unified, Pythonic environment that handles the entire pipeline from raw imaging to advanced signal processing.

Methods and Implementation

The MNE-Python localization suite introduces several key technical advancements designed to improve both the accuracy and ease of the localization process.

Automated Imaging Alignment

The pipeline utilizes the DIPY library to perform automated co-registration of CT and MRI volumes. This is achieved through a mutual information histogram-matching approach, which robustly aligns the two modalities despite their different contrast properties.

Alignment of postoperative CT (red) with preoperative MRI.

Interactive Localization GUI

A central feature of the tool is the mne.gui.locate_ieeg interface. Built on PyQt, this GUI allows users to navigate through 2D orthogonal slices of the aligned volumes while simultaneously viewing a real-time 3D rendering of the brain and electrode trajectories. This dual-view approach is critical for distinguishing between different electrode shafts in sEEG or grid rows in ECoG.

The interactive GUI for electrode localization in MNE-Python, showing 2D slices and a 3D reconstruction.

Precision and Correction Tools

To minimize human error, the "Snap to Center" feature automatically refines user-placed markers by calculating the center of mass of high-intensity voxels in the CT scan. Furthermore, the software includes a brain shift correction routine. During surgery, intracranial pressure changes can cause the brain to shift; the tool compensates for this by projecting ECoG sensors back onto the pial surface, preventing electrodes from appearing inside brain tissue in the final model.

Advanced Template Warping

For group studies, individual brain data must be mapped to a template (e.g., Freesurfer's fsaverage). While older methods used linear transformations, MNE-Python implements Symmetric Diffeomorphic Registration (SDR). This non-linear mapping significantly improves the accuracy of fitting an individual's anatomy to a template, ensuring that electrodes are correctly localized relative to cortical structures across subjects.

Key Insights and Results

The integration of localization tools within MNE-Python offers several distinct advantages:

  • Workflow Continuity: Researchers can transition from image alignment to time-frequency or connectivity analysis without the risk of data corruption inherent in exporting between different software environments.
  • Computational Efficiency: The SDR morphing implementation is highly optimized, reducing processing time from several hours in some legacy systems to approximately 15 minutes.
  • Reliability: As part of the core MNE-Python package, the tool benefits from extensive unit testing and continuous integration, ensuring stability across Windows, macOS, and Linux platforms.

Qualitative assessments demonstrate that the use of non-linear SDR warping prevents common errors seen in linear mapping, such as electrodes appearing to "float" outside the brain surface in template space.

Limitations and Future Directions

While the automated alignment is robust, it may occasionally require manual "seeding" in cases of poor initial orientation. Additionally, the current workflow still involves manual labeling of electrode contacts within the GUI. Future work will focus on increasing automation through machine learning techniques to automatically detect and label electrode contacts in CT scans, further reducing the manual effort required for large-scale studies.

Conclusion

The MNE-Python localization pipeline represents a significant step forward for the iEEG community. By providing a free, open-source, and integrated solution, it lowers the barrier to entry for high-quality anatomical localization and promotes reproducible research in intracranial electrophysiology.

Summary updated

BibTeX
@article{rockhill2022intracranial,
  author = {Alexander Rockhill and Eric Larson and Brittany Stedelin and Alessandra Mantovani and Ahmed M. Raslan and Alexandre Gramfort and Nicole C. Swann and Alexander P. Rockhill and Eric B. Larson and Alessandra Madia Mantovani},
  title = {{Intracranial Electrode Location and Analysis in MNE-Python}},
  journal = {J. Open Source Softw.},
  year = {2022},
  doi = {10.21105/joss.03897},
}
Figure