mrisegmentation
🧠Automatic MRI segmentation pipeline for consistent FEM and BEM mesh creation from MRI scans of human heads
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 22 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
â—‹Academic email domains
-
â—‹Institutional organization owner
-
â—‹JOSS paper metadata
-
â—‹Scientific vocabulary similarity
Low similarity (6.6%) to scientific vocabulary
Repository
🧠Automatic MRI segmentation pipeline for consistent FEM and BEM mesh creation from MRI scans of human heads
Basic Info
- Host: GitHub
- Owner: harmening
- License: gpl-3.0
- Language: MATLAB
- Default Branch: master
- Size: 1.3 MB
Statistics
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
- Releases: 1
Metadata Files
README.md
MRIsegmentation
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
Prerequisites
This segmentation pipeline connects these awesome open source projects:
- 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]
How to get up and running:
- Install Matlab and its NIfTI and ANALYZE tools. <!---
- Install fieldtrip. SPM12 should come with it; if not, install it, too.
- Download ATRA for Linux / Mac into
/usr/local/art/. ---> - Run the following commands in a terminal:
```bash
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/cat12r2159.zip $ rm -r ./fieldtrip/external/spm12/toolbox/cat12 $ unzip cat12r2159.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/Huangetal2013.zip $ unzip Huangetal2013.zip -d ./Huangetal2013 $ rm Huangetal2013.zip
Minor changes to make new_segment storing the nonlinear warp
$ sed -i.bak 's/warp.write = [0 0]/warp.write = [1 1]/' Huangetal2013/startseg.m && rm Huangetal2013/startseg.m.bak
- The coordinate systems are defined by the MRI scanner's coordinate systems. For optional [translation into the ACPC-coordinate system](#translation-to-acpc) before segmentation, download [atra for linux](https://www.nitrc.org/frs/download.php/10393/atra1.0_LinuxCentOS6.7.tar.gz/?i_agree=1&release_id=3672) (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:<br>
bash
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](https://pages.stat.wisc.edu/~mchung/research/amygdala/SPHARMsmooth2.m), [SPHARMvectorize.m](https://pages.stat.wisc.edu/~mchung/softwares/weighted-SPHARM/SPHARMvectorize.m)) into./weighted-SPHARM` by following the description of Chung et al..
How to start segmentation:
- The MRI scan needs to be in NIfTI file format (.nii or .nii.gz).
bash # Change parameters in start_segmentation.m and run $ matlab -r "start_segmentation(./example_head/T1.nii); exit;"<!--- # Or alternatively in parallel: $ python parallel.py ./data/MRIscan1/T1.nii ./data/MRIscan2/T1.img ./data/MRI_scan3/T1.nii.gz --->
Translation to ACPC
- 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].
Tissue segmentation
- 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 (Huangetal_2013/eTPM.nii) developed in [3] is used.
- The calculated probability distributions are stored (c1, c2, ..) and converted
into binary masks for each tissue (maskscalp.nii, maskskull.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.
Mesh construction
- 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.
Correction and smoothing
- 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.
Electrode alignement
- 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.
Sourcemodel creation
- 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 to fiducial based coordinate systems
- 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.
Representing the cortical surface in Spherical Harmonics (SPHARM)
- 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].
Troubleshooting
- 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.lmand 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.lmand restart the segmentation. For more details refer to getting started with atra or atra youtube tutorial. <!--- mri = ftreadmri('/fullpath/to/example.nii'); cfg = []; cfg.anaparameter = 'anatomy'; ft_sourceplot(cfg, mri); --->
Citing
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}
}
References
[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.
<!--- \cite{Ardekani09} --->
[2] John Ashburner, Karl J. Friston. "Unified segmentation" NeuroImage, (2005): 26(3), 839 - 851. doi:10.1016/j.neuroimage.2005.02.018.
<!--- \cite{Ashburner05} --->
[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.
<!--- \cite{Huang2013} --->
[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.
<!--- \cite{Fang2009} --->
[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.
<!--- \cite{Gaser2016} --->
[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.
<!--- \cite{Fieldtrip11} --->
[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.
<!--- \cite{Chung2007} --->
[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.
<!--- \cite{OASIS2007} --->
Owner
- Name: nils
- Login: harmening
- Kind: user
- Location: Berlin, Germany
- Company: Neurotechnology group, TU Berlin
- Repositories: 2
- Profile: https://github.com/harmening
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - given-names: "Nils" family-names: "Harmening" orcid: "https://orcid.org/0000-0002-4150-1915" affiliation: Technische Universität Berlin - given-names: "Daniel" family-names: "Miklody" orcid: "https://orcid.org/0000-0002-8709-4200" affiliation: Technische Universität Berlin title: "MRIsegmentation" version: 1.1 doi: 10.5281/zenodo.7357674 url: "https://oi.org/10.5281/zenodo.7357674" url: "https://github.com/harmening/MRIsegmentation" date-released: 2022-11-24
GitHub Events
Total
- Issues event: 2
- Watch event: 8
- Issue comment event: 1
- Push event: 1
Last Year
- Issues event: 2
- Watch event: 8
- Issue comment event: 1
- Push event: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 0
- Average time to close issues: about 1 month
- Average time to close pull requests: N/A
- Total issue authors: 1
- Total pull request authors: 0
- Average comments per issue: 1.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: about 1 month
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 1.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- marcsous (1)