mri2mesh

Warning

Mri2mesh is deprecated. Please use charm instead.

Description

mri2mesh reconstructs a tetrahedral head mesh from T1- and T2-weighted structural MR images. It runs also with only a T1w image, but will create better skull segmentations when also a T2w image is available.

Attention

mri2mesh depends on FreeSurfer (5.3.0 or newer) and FSL (5.0.5 or newer), and is therefore not compatible with Windows. Please see Optional Dependencies for instructions on how to set-up FreeSurfer and FSL

Usage example

  1. Open a terminal and go to the directory of the “Ernie” example data set.

  2. Run the reconstruction:

mri2mesh --all ernie org/ernie_T1.nii.gz org/ernie_T2.nii.gz

The argument --all tells mri2mesh to run all reconstruction steps including volume meshing. The subject ID (subID) ernie is given next. Mri2mesh will create a mesh named ernie.msh, a folder fs_ernie/ that contains the FreeSurfer results, and a folder m2m_ernie/ that contains the files that are needed for volume meshing. The input images are given as final arguments (first the T1, then the T2). When calling mri2mesh --all the first time for a dataset, it will run FreeSurfer on it using the T1 as input. This is quite time-consuming. When re-running mri2mesh --all it will use the existing FreeSurfer results, shortening the time required to ~3-4 hours.

Alternatively, the reconstruction can be run with only the T1w image as input, but this will result in a less accurate skull region:

mri2mesh --all ernie org/ernie_T1fs.nii.gz

  1. Check the results:

mri2mesh -c ernie

This will show the reconstructed surfaces overlaid over the MR images using freeview. The red lines indicate the final surfaces used for volume meshing, the yellow indicate the GM and WM surfaces created by FreeSurfer. A second freeview will show the subject T1 overlaid on the MNI template for a visual check of the registration accuracy. In addition, you should have a look at the tetrahedral head mesh by loading it into gmsh.

Further notes

  • A quick check can be performed by looking at the final volume masks overlaid over the structural images in fslview: mri2mesh --qc ernie

  • As a standard, mri2mesh uses 60000 triangles for each white matter surface, and the number of triangles for the other surfaces are scaled relative to this number. This results in a volume mesh of ~3.5 million tetrahedra. Alternatively, you can adjust the mesh resolution by setting --numvertices=<mynumber>.

  • After the head mesh creation, temporary files are deleted to save disk-space. Adding --nocleanup prevents this.

  • When setting --t2pial, FreeSurfer will use the T2 image to improve the estimate of the pial surfaces (recommended only for high-res with T2 images 1mm iso voxel).

  • Manual editing: For improving the GM and WM surfaces after the first run of mri2mesh, edit the FreeSurfer results as described on the FreeSurfer wiki. Then run mri2mesh again with the --all option, as stated above. mri2mesh will use the edited FreeSurfer results to create a new head mesh. For improving the ventricles, cerebellum, csf, skull or skin surfaces, manually edit one or more of the binary masks stored in m2m_subID/mask_prep/. Then run mri2mesh again wit the --all and --keep_masks options. The latter option will prevent mri2mesh from overwriting the edited masks.

  • Transformation from and to MNI space: Both positions and results such as the electric field can be transformed between MNI and subject space. Please see below for a description of the corresponding command line programs. The transformation is based on a non-linear whole-head registration of the T1 of the subject to the MNI template, using FSL’s fnirt command. Even though fnirt was developed for registering the brain, usually acceptable results are achieved by mri2mesh for the whole head. When a T1 without fat suppression is used as input, the bright skull might be warped into the skin or brain. Using the option –mnimaskskull can prevent this. A skull mask will then be applied to down-weight the skull intensity. The transformations are stored in the toMNI subdirectory of the m2m_subID/ folder. Subject space is defined by the qform set in the subID_T1fs_conform.nii.gz, which can be found in the same folder as the head mesh.

  • When something goes wrong, you can check the m2m_subID/mri2mesh_log.html file.

References

Windhoff, M., Opitz, A., and Thielscher, A. (2013). Electric field calculations in brain stimulation based on finite elements: an optimized processing pipeline for the generation and usage of accurate individual head models. Human brain mapping, 34(4), 923-935.