Automatic MRI segmentation pipeline for consistent FEM and BEM mesh creation from MRI scans of human heads
0. Install prerequisites
1. Translation to ACPC-coordinate system
2. Tissue segmentation (Scalp, Skull, CSF, White Matter, Gray Matter)
3. Surface and Volume Mesh construction
4. Correction and smoothing of segmentation mistakes
5. Alignement of electrodes (and sourcemodels)
6. Cortical sourcemodel creation
7. Transformation to fiducial based coordinate systems
8. Representing the cortical surface in Spherical Harmonics (SPHARM)
9. Troubleshooting
A. References
- Automatic Temporal Registration Algorithm (ATRA) [1]
- Statistical Parametric Mapping (SPM12)
- Andy's tools [3]
- iso2mesh [4]
- Computational Anatomy Toolbox (CAT12) [5]
- fieldtrip [6]
- weighted SPHARM [7]
- Open Access Series of Imaging Studies (OASIS) [8]
- Install Matlab and its NIfTI and ANALYZE tools.
- Run the following commands in a terminal:
# Clone repository
$ git clone https://github.com/harmening/MRIsegmentation.git
$ cd MRIsegmentation
# Install fieldtrip
$ git clone https://github.com/fieldtrip/fieldtrip.git
# Install SPM12
$ wget -P ./ https://www.fil.ion.ucl.ac.uk/spm/download/restricted/eldorado/spm12.zip
$ rm -r ./fieldtrip/external/spm12
$ unzip spm12.zip -d ./fieldtrip/external/
$ cd ./fieldtrip/external/spm12/src
$ make distclean
$ make && make install
$ make external-distclean
$ make external && make external-install
$ cd ../../../../ && rm spm12.zip
# Install CAT12
$ wget -P ./ http://www.neuro.uni-jena.de/cat12/cat12_r2159.zip
$ rm -r ./fieldtrip/external/spm12/toolbox/cat12
$ unzip cat12_r2159.zip -d ./fieldtrip/external/spm12/toolbox/
$ rm cat12_r2159.zip
# Install iso2mesh
$ git clone https://github.com/fangq/iso2mesh.git
# Download Andy's tools
$ wget -P ./ https://www.parralab.org/segment/Huang_et_al_2013.zip
$ unzip Huang_et_al_2013.zip -d ./Huang_et_al_2013
$ rm Huang_et_al_2013.zip
# Minor changes to make new_segment storing the nonlinear warp
$ sed -i.bak 's/warp\.write = \[0 0\]/warp\.write = \[1 1\]/' Huang_et_al_2013/start_seg.m && rm Huang_et_al_2013/start_seg.m.bak
- The coordinate systems are defined by the MRI scanner's coordinate systems. For optional translation into the ACPC-coordinate system before segmentation, download atra for linux (register at nitrc.org, agree to the license terms), move the downloaded
atra1.0_LinuxCentOS6.7.tar.gz
into./art
and run the following commands in a terminal:
# Install atra
$ export ARTHOME="$(pwd)/art"; export PATH=$ARTHOME/bin:$PATH
$ cd $ARTHOME
$ gunzip atra1.0_*.tar.gz
$ tar -xvf atra1.0_*.tar
$ rm atra1.0_*.tar; rm atra1.0_*.tar.gz;
- If desired, download the weighted-SPHARM (
SPHARMsmooth2.m
,SPHARMvectorize.m
) into./weighted-SPHARM
by following the description of Chung et al..
- The MRI scan needs to be in NIfTI file format (.nii or .nii.gz).
# Change parameters in start_segmentation.m and run
$ matlab -r "start_segmentation(./example_head/T1.nii); exit;"
- Anatomical landmark detection, especially anterior and posterior
commissures (AC/PC). - Reorientation from MRI scanner coordinates into the comparable ACPC
coordinate system (origin at AC, RAS orientation (x = right, y = anterior,
z = superior), original size i.e. not normalized to a template) - For more details refer to [1].
- The posterior probability of each MRI voxel belonging to a specific tissue type
(scalp, skull, cerebrospinal fluid (CSF), gray matter (GM), white matter(WM))
is estimated by the "Unified Segmentation" framework of [2] as implemented
as new_segment in SPM12. - As prior probability distribution template the extended tissue probability map (Huang_et_al_2013/eTPM.nii) developed in [3] is used.
- The calculated probability distributions are stored (c1, c2, ..) and converted
into binary masks for each tissue (mask_scalp.nii, mask_skull.nii, ..), followed
by smoothing using a Gaussian low-pass filter using Andys tools [3]. - The following automatic correction of obvious morphological errors includes assigning unassigned voxels and reclassifying GM voxels, that are directly adjacent to skull voxels, as CSF voxels in order to avoid potential CSF discontinuities. The final segmented MRI is stored as segmentedmri.mat.
- Boundary surface meshes per tissue are triangulated with cgalsurf as
implemented in the fieldtrip toolbox [6]. From these meshes (bnd5.mat)
and (bnd4.mat, merged GM and WM to one cortex mesh) corresponding
5-shell and 4-shell Boundary Element Method (BEM) models can be built. - A volumetric tetrahedral mesh is constructed using vol2mesh [4].
Using cgalmesh it creates high-quality Delaunay tetraeder (see
plotted tissued voxels to the right), that can be used for Finite
Element Method (FEM) modelling. Nodes, faces, elements and voxel
labels are stored as mesh5.mat.
- Tests on the OASIS1 database of 416 human heads [8] revealed, that
10 out of 416 segmentations needed further correction of the cortical
surface mesh only (see segmentation error and correction to the right). - The correction is done by recalculating abnormal vertex positions
(as in example to the right) relative to their neighboring mesh nodes. - For an extra smooth cortex (GM+WM) surface a further Laplace flow
mesh smoothing is applied.
- Nonlinear alignment of standard electrode positions by using SPMs nonlinear,
voxel-wise transformation mapping from the eTPM (in MNI space) to the individual head coordinates. - Refinement of electrode positions by projecting them directly onto the segmented scalp mesh. This small projection corrects for minimal mesh approximation errors and ensures that all electrodes are perfectly placed on the outermost mesh and thus can be used directly for BEM modelling.
- Accurate nonlinear warping of fiducials (nasion (NAS), left and right pre-auricular (LPA/RPA)) gained from manual expert selection on a high resolution segmentation.
- EEG source model estimation by using CATs [5] accurate cortex segmentation and
cortical thickness determination. - A source model surface mesh is created at 2/3 distance between the gray and white matter surface using the cortical thickness estimation.
- The mesh vertices constitute the source model positions. The equivalent current dipoles are orientated according to their outwards pointing mesh normals.
- Transformation of meshes, electrode positions and sourcemodels to coordinate systems, that are based on individual fiducical positions (e.g. CTF).
- The individual fiducials (NAS, LPA, RPA) are gained through SPMs nonlinear mapping from the eTPM template.
- The weighed spherical harmonic (weighted-SPHARM) representation can express the cortical surface as a weighted linear combination of spherical harmonics.
- Since SPHARM is a better basis for the proper description of the cortex folding as the euclidean space, it is used in many different applications [7].
- SPM12 sometimes fails due to fieldtrip routines replacing standard matlab
routines. Make sure to delete (or remove from matlab search path) older matlab version folders from
./fieldtrip/compat/
and./fieldtrip/external/spm12/external/fieldtrip/compat/
. For more information visit https://github.com/fieldtrip/fieldtrip/blob/master/compat. - Atra sometimes fails to correctly detect anatomical landmarks and one
needs to manually specify the voxel coordinates of AC, PC and the vertex of
the superior pontine sulcus (VSPS). Delete all files from your MRI folder
exept the original MRI and the file
imagelist
. Create a new file calledlandmarks.lm
and write the voxel coordinates of AC, PC and VSPS in the first, second and third line, respectively, seperated by one whitespace. Openimagelist
, write the fullpath into the second line oflandmarks.lm
and restart the segmentation. For more details refer to getting started with atra or atra youtube tutorial.
If you find MRIsegmentation useful for your research, please consider citing:
@software{Harmening_MRIsegmentation_2022,
author = {Harmening, Nils and Miklody, Daniel},
doi = {10.5281/zenodo.7357674},
month = {11},
title = {{MRIsegmentation}},
url = {https://github.com/harmening/MRIsegmentation},
version = {1.1},
year = {2022}
}
[1] Babak A. Ardekani and Alvin H. Bachman. "Model-based automatic detection of the anterior and posterior commissures on MRI scans" NeuroImage, (2009): 46(3), 677 - 682. doi:10.1016/j.neuroimage.2009.02.030
.
[2] John Ashburner, Karl J. Friston. "Unified segmentation" NeuroImage, (2005): 26(3), 839 - 851. doi:10.1016/j.neuroimage.2005.02.018
.
[3] Yu Huang, Jacek Dmochowski, Yuzhuo Su, Abhishek Datta, Chris Rorden, Lucas Parra. "Automated MRI Segmentation for Individualized Modeling of Current Flow in the Human Head" Journal of Neural Engineering, (2013): 10, 066004. doi:10.1088/1741-2560/10/6/066004
.
[4] Qianqian Fang, David A. Boas. "Tetrahedral Mesh Generation from Volumetric Binary and Gray-Scale Images" Proceedings of IEEE International Symposium on Biomedical Imaging, (2009), 1142-1145. doi:10.1109/ISBI.2009.5193259
.
[5] Christian Gaser, Robert Dahnke. "CAT - A Computational Anatomy Toolbox for the Analysis of Structural MRI Data" (2016): http://www.neuro.uni-jena.de/hbm2016/GaserHBM2016.pdf.
[6] Robert Oostenveld, Pascal Fries, Eric Maris, Jan-Mathijs Schoffelen. "FieldTrip: Open Source Software for Advanced Analysis of MEG, EEG, and Invasive Electrophysiological Data" Computational intelligence and neuroscience, (2011), 156869. doi:10.1155/2011/156869
.
[7] Moo K. Chung, Kim M. Dalton, Li Shen, Alan C. Evans, Richard J. Davidson. "Weighted Fourier Series Representation and Its Application to Quantifying the Amount of Gray Matter" IEEE Transactions on Mecical Imaging, (2007): 26(4). 10.1109/TMI.2007.892519
.
[8] Daniel S. Marcus, Tracy H. Wang, Jamie Parker, John G. Csernansky, John C. Morris, Randy L. Buckner. "Open Access Series of Imaging Studies (OASIS): Cross-sectional MRI Data in Young, Middle Aged, Nondemented, and Demented Older Adults" Journal of Cognitive Neuroscience, (2007): 19(9), 1498-1507. doi:10.1162/jocn.2007.19.9.1498
.