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.

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

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.

Tutorials/SegFastSurfer (last edited 2021-11-18 11:10:27 by FrancoisTadel)