MRI segmentation with FastSurfer

Authors: Francois Tadel

The open-source software FastSurfer can be used to extract the cortical envelope from a T1 MRI and register it to an atlas. The process is fully automatic, the results are compatible with FreeSurfer. If you are using FastSurfer, please cite the appropriate references. Note that this software is available only for Linux and MacOS.

Cite FastSurfer

If you use FastSurfer for MRI segmentation, please cite the following article in your publications:

Henschel L, Conjeti S, Estrada S, Diers K, Fisch B, Reuter M
FastSurfer - A fast and accurate deep learning based neuroimaging pipeline
NeuroImage, Oct 2020

Install FastSurfer

The most complicated task will be to install FastSurfer. Unfortunately, Brainstorm cannot do that automatically yet. If you are using Ubuntu 20, you may try the procedure below. Otherwise, refer to the intructions in the FastSurfer GitHub repository.

Install pyenv: Python 3.6

From a terminal, install the required packages:

$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
  libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
  libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl

Install pyenv:

$ curl https://pyenv.run | bash

Add the following lines at the end of the file $HOME/.bashrc:

# Load pyenv-virtualenv automatically
export PATH="$HOME/.pyenv/bin:$HOME/.pyenv/shims:$PATH"
eval "$(pyenv init -)"eval "$(pyenv virtualenv-init -)"

Start a new terminal, install Python 3.6 and create a new virtual environment for FastSurfer:

$ pyenv install 3.6.15
$ pyenv global 3.6.15
$ pyenv virtualenv fastsurfer

For complete and updated installation instruction, see the pyenv repository.

Install FreeSurfer 6.0.1

Note that FastSurfer works only with FreeSurfer 6. Newer versions of FreeSurfer are not supported at the moment. If you try using FreeSurfer 7, you would get an error message when running recon-surf.

Install the required packages:

$ apt-get -y install bc binutils libgomp1 perl psmisc sudo tar tcsh unzip \
             uuid-dev vim-common libjpeg62-dev

Download and install FreeSurfer 6.0.1:

$ cd ~/
$ wget https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/6.0.1/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1.tar.gz
$ tar xzvf freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1.tar.gz
$ sudo mkdir /usr/local/freesurfer
$ sudo mv freesurfer /usr/local/freesurfer/6.0.1

Obtain a license.txt file from this page, and copy it to the installation folder:

$ cp license.txt /usr/local/freesurfer/6.0.1/

Add the following lines at the end of the file $HOME/.bashrc:

# FreeSurfer
export FREESURFER_HOME=/usr/local/freesurfer/6.0.1/
source $FREESURFER_HOME/SetUpFreeSurfer.sh

Close the terminal and open a new one, you should see the following message:

-------- freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1-f53a55a --------
Setting up environment for FreeSurfer/FS-FAST (and FSL)
FREESURFER_HOME   /usr/local/freesurfer/6.0.1
FSFAST_HOME       /usr/local/freesurfer/6.0.1/fsfast
FSF_OUTPUT_FORMAT nii.gz
SUBJECTS_DIR      /usr/local/freesurfer/6.0.1/subjects
MNI_DIR           /usr/local/freesurfer/6.0.1/mni

For complete and updated installation instructions, see the FreeSurfer wiki.

Install FastSurfer

Clone the FastSurfer GitHub repository:

$ cd ~/
$ git clone https://github.com/Deep-MI/FastSurfer.git

Install the required packages:

$ sudo apt install libblas-dev liblapack-dev libatlas-base-dev gfortran
$ cd FastSurfer
$ pip install -r requirements.txt

Add the following lines at the end of the file $HOME/.bashrc:

# Add FastSurfer to PATH
export PATH="$HOME/FastSurfer:$PATH"

Execute FastSurfer manually:

$ ./run_fastsurfer.sh --t1 /home/ftadel/segmentation/freesurfer_db/PD/mri/orig/001.mgz \
  --sid PD --sd /home/ftadel/segmentation/fastsurfer_db --batch 4 --parallel --threads 4

This default configuration would run FastSurfer on the CPU. If you have access to GPU resources and have the CUDA libraries installed on your system, you could make FastSurfer run much faster. See the documentation on the FastSurfer GitHub repository.

Run FastSurfer from Brainstorm

Cortical parcellations

One of the typical FreeSurfer cortex parcellations is available at the end of the process:

Volume parcellations

Two of the typical FreeSurfer volume parcellations are available at the end of the process:

Subcortical structures: aseg atlas

The file aseg.mgz contains a volume atlas of 40 subcortical regions. Brainstorm reads these volume labels and tesselates some of these regions, groups all the meshes in a large surface file where the regions are identified in an atlas called "Structures". It identifies: 8 bialateral structures (accumbens, amygdala, caudate, hippocampus, pallidum, putamen, thalamus, cerebellum) and 1 central structure (brainstem).

You can easily extract one structure (for example the brainstem or the cerebellum) by selecting the corresponding entries in the scouts list and selecting the menu Scout > Edit surface > Keep only selected scouts. It creates a new surface with only the selected regions. If you want to remove one or several structures, use the menu "Remove selected scouts" instead. More information.

Read more about the FreeSurfer subcortical atlas on the software wiki:
http://ftp.nmr.mgh.harvard.edu/fswiki/SubcorticalSegmentation

Registered spheres

The registered spheres are saved in each surface file in the field Reg.Sphere.Vertices. There is nothing that can be done with this information at this point, but it will become helpful when projecting the source results from the individual brains to the default anatomy of the protocol, for a group analysis of the results: Subject coregistration.

Read more about the FreeSurfer registration process on the software wiki:
https://surfer.nmr.mgh.harvard.edu/fswiki/SurfaceRegAndTemplates

Tutorials/SegFastSurfer (last edited 2021-12-01 12:28:51 by FrancoisTadel)