A Brief introduction to BEaST

Submitted by conge on
By Qingyang Li

Introduction

BEaST is a software toolkit to extract brain from hight resolution T1 images. BEaST refers to Brain Extraction based on nonlocal Segmentation Technique which was published in Neuroimage by Eskildsen and colleagues (Eskildsen et al, 2012).

Brain extraction is a very important image processing step in MRI or fMRI data processing analysis. The analysis of cortical thickness and voxel-based morphometry require accurate estimation and segmentation of tissue type. Brain extraction also plays an important role in the image registration step since some image processing software (e.g. AFNI and FSL) requires a skull-stripped brain as target of linear registration between T1 image and functional image. The most commonly used brain extraction packages like AFNI's 3dSkullStrip, FSL's BET and the segmentation module of Freesurfer(http://ftp.nmr.mgh.harvard.edu/fswiki/FreeSurferWiki) often works but can not deliver robust results.

In fact, I found a lot of T1 images from ABIDE dataset could not be skullstripped cleanly by 3dSkullStrip or Freesurfer even when I tweaked a lot of parameters (Figure 1). I also tried BET, but the problem of BET is that it often clips into grey matter instead of leaving skull. BEaST came to my attention and I tried it and it gave much reliable results as far as I can tell, (See figure 1 below)

Figure 1

Figure 1: Skull Stripping (or brain extration) results by BEaST, AFNI's 3dSkullStrip and FreeSurfer for one of subjects from ABIDE.

My bottom line is, BEaST is a better alternative for BET, 3dSkullStrip and Freesurfer for brain extraction. It at least worth a try if the “main stream” packages fail to meet your needs. In my process of trying BEaST, I found the lack of documentation is an issue. This concise guide is created to provide a documentation from a user's perspective to help potential BEaST users to get started easily.

In this documentation, I'll 1) document the installation procedures of BEaST on a linux box running Ubuntu 10.04 LTS; 2) Provide code I created to process images using BEaST; 3) share my thoughts on the software. Hope it will be useful to help people start using BEaST.

I. Concise installation guide

Dependencies of BEaST

1. Install MINC Tool Kit:go to this page for the toolkit and it's installation guide for your system. If your system is Ubuntu 10.04, you can run the code below.

wget http://packages.bic.mni.mcgill.ca/minc-toolkit/Debian/minc-toolkit-0.3.16-20121113-Ubuntu_10.04-x86_64.deb
sudo apt-get install libc6 libstdc++6 imagemagick perl freeglut3 libxcb1 libxdmcp6 libx11-6 libxext6 libxau6 libuuid1 libjpeg62 libexpat1 libtiff4
sudo dpkg -i minc-toolkit-0.3.16-20121113-Ubuntu_10.04-x86_64.deb 
source /opt/minc/minc-toolkit-config.sh 

IMPORTANT NOTES

NOTE 1: please add source /opt/minc/minc-toolkit-config.sh into your bashrc file so you don't have to do it every time before running the toolkit.
echo "source /opt/minc/minc-toolkit-config.sh" >> ~/.bashrc;

NOTE 2: The current version of MINC tool kit has a bug in one of it's scripts which is called bestlinreg_s, you need to fix the problem by changing line 30 of the bestlinreg_s script:
trans => qw/-est_translations/,
to:
trans => [qw/-est_translations/],

2. Install NIfTI librarie

sudo apt-get install libnifti-dev

3. Install libariry for Hierarchical Data Format 5 support

sudo apt-get install libhdf5-serial-dev

Install BEaST

1. Download BEaST Source cod.

cd ~/Downloads
wget http://www.bic.mni.mcgill.ca/uploads/ServicesSoftwareAdvancedImageProcessingTools/beast-1.15.tar.gz
tar -xzvf beast-1.15.tar.gz 
cd beast-1.15

The README file is also available online: Click here to Read.

2. Compile and Install BEaST

Run the code below to configure the installation.

ccmake CMakeLists.txt

At the step, you need to make sure all the path is correct in the CMakeList.txt. Type “c” to configure the installation and type “g” to generate configuration. If everything is correct, runt the code below to install BEaST to your system

make
sudo make install

3. Install BEaST Libraries

cd ~/Downloads
wget http://packages.bic.mni.mcgill.ca/tgz/beast-library-1.1.tar.gz
tar xzf beast-library-1.1.tar.gz
sudo mv beast-library-1.1 /opt/minc/share/

4. Get the MNI ICBM152 template

mkdir -p ~/Atlas
cd ~/Atlas/
wget http://www.bic.mni.mcgill.ca/~vfonov/icbm/2009/mni_icbm152_nlin_sym_09c_minc2.zip
unzip mni_icbm152_nlin_sym_09c_minc2.zip

Now BEaST is installed, what's next?

OK, before you do anything else, pleaes take a step back and start reading some important notes by the authors of the software.

  • Read the README file of BEaST.

    more ~/Downloads/beast-1.1/README

  • See README.library file for detailed installation guide.

    more ~/Downloads/beast-1.1/README.library

II. Script for Brain Extraction using BEaST

The data I handle on a daily basis are NIFTI files which is not directly supported by BEaST yet. So I created a script which can accept NIFTI files as input and output result file in NIFTI format. The script needs a correctly installed AFNI to work. Please visit AFNI's website for installation guide if you do not have AFNI already.

Other dependencies of the script

1. MINC Tool Kit is installed and can be called from command line (See above or here for instructions); 2. You have BEaST libraries installed (See above or here for instructions) and you know the path to them. 3. You have the MNI ICBM152 template, which is 193x229x193. You can download the template here. I am using the 2009c version. you need to known the path to the templates.

See the following bash script. I have tried about 40 T1 images with the script. The typical run time for processing 1 data set is about an hour.

Save the code below as BEaSTSkullStrip.sh and make it executable.

#!/usr/bin/env bash
# 
# BEaSTSkullStrip.sh
# Using BEaST to do SkullStriping
# [see here](https://github.com/FCP-INDI/C-PAC/wiki/Concise-Installation-Guide-for-BEaST) for instructions for BEaST.
# 
# Qingyang Li
# 2013-07-29
#  
# The script requires AFNI, BEaST, MINC toolkit.

MincPATH='/opt/minc'
source $MincPATH/minc-toolkit-config.sh

MincLibPATH="$MincPATH/share/beast-library-1.1/"

MNItemplatePATH='~/Atlas/mni_icbm152_t1_tal_nlin_sym_09c_minc2'

cwd=`pwd`

if [ $# -lt 1  ]
then 
  echo " USAGE ::  "
  echo "  BEaSTSkullStrip.sh <input> [output prefix] " 
  echo "   input: anatomical image with skull, in nifti format " 
  echo "   output: The probram will output two nifti files " 
  echo "      1) a skull stripped brain image; "  
  echo "      2) a skull stripped brain mask. "
  echo "   Option: output prefix: the filename of the output files without extention"
  echo " Example: BEaSTSkullStrip.sh ~/data/head.nii.gz ~/brain " 
  exit
fi

if [ $# -eq 1 ]
then
  inputDir=$(dirname $1)
  if [ $inputDir == "." ]; then
    inputDir=$cwd
  fi

  filename=$(basename $1)
  inputFile=$inputDir/$filename

  extension="${filename##*.}"
  if [ $extension == "gz" ]; then
    filename="${filename%.*}"
  fi
  filename="${filename%.*}"

  out=$inputDir/$filename

else
  outputDir=$(dirname $2)
  if [ $outputDir == "." ]; then
  outputDir=$cwd
  out=$outputDir/$2
  else
    mkdir -p $outputDir
    out=$2
  fi

fi

workingDir=`mktemp -d`
echo " ++ working directory is $workingDir"
cd $workingDir
3dcopy $inputFile head.nii
nii2mnc head.nii head.mnc

flist=head.mnc
# Normalize the input
beast_normalize head.mnc head_mni.mnc anat2mni.xfm -modeldir $MNItemplatePATH
flist="$flist head_mni.mnc anat2mni.xfm"

# Run BEaST to do SkullStripping
# configuration file can be replaced by $MincLibPATH/default.2mm.conf or $MincLibPATH/default.4mm.conf

mincbeast -fill -median -conf $MincLibPATH/default.1mm.conf $MincLibPATH head_mni.mnc brain_mask_mni.mnc
flist="$flist brain_mask_mni.mnc"

# Trasform brain mask to it's original space
mincresample -invert_transformation -like head.mnc -transformation anat2mni.xfm brain_mask_mni.mnc brain_mask.mnc
flist="$flist brain_mask.mnc"

# Convert image from MNC to NII format.

mnc2nii brain_mask.mnc brain_mask_tmp.nii
3dresample -orient RPI -inset brain_mask_tmp.nii -prefix brain_mask_orig.nii
flist="$flist rain_mask_tmp.nii brain_mask_orig.nii"

# Generate and output brain image and brain mask
3dcalc -a brain_mask_orig.nii -b head.nii -expr "a*b" -prefix head_brain.nii.gz

flist="$flist head_brain.nii"

# out put files

# fix the AFNI won't overwrite problem.
rm -rf ${out}_brainmask.nii.gz ${out}_brain.nii.gz

3dcopy -inset brain_mask_orig.nii ${out}_brainmask.nii.gz
3dcopy -orient RPI -inset head_brain.nii.gz ${out}_brain.nii.gz

# delete all intermediate files
#rm -rf $flist
echo "  ++ working directory is $workingDir"
cd $cwd

III. Q & A about BEaST

I asked a lot of questions about BEaST when I was learning to use it. The questions are answered by Dr. Eskildsen. I think these are useful input users might not be able to get easily from the web. I put them here for your references.

BEaST parameters

BEaST use .conf files to specify the configurations. Below are message I got from Dr. Eskildsen explaining the meaning of the parameters in config file and arguments of the best command.

The main parameters are those in the configuration files. You should always set them in the conf-file instead of at the command line. For example, the conf. file (default.2mm.conf) I usually uses looks like this:

# voxelsize patchsize searcharea alpha beta threshold num_selected
2 1 4 0.5 0.25 0.95 20
4 1 2 0.2 0.25 0.95 20

Each line represent a scale step. Here there are two steps, 4mm and 2mm. The default.1mm.conf file contains one more line for the 1mm scale step. Beast only supports these three different scales, so you cannot add e.g. 8mm or 0.5mm.

The header shows the parameter names. voxelsize is on of 1, 2, or 4 indicating the scale step. Beast always starts with the largest voxelsize and propagates the segmentation to the next scale. The propagation is controlled by alpha, which determine how much information is propagated. Here alpha is 0.2 for the 4mm scale, which means that probabilities in the range 0.2 - 0.8 are propagated, while <0.2 are background and >0.8 are foreground (object). If you increase alpha, you trust your lowres segmentation more and propagate less to the next scale. For the final scale alpha is usually 0.5, because this is the threshold for the final segmentation. You can adjust this final threshold to control consistent over/under-segmentation.

patchsize is the size of the patch when comparing structures across the library. 1 means 3x3x3 patch, 2 means 5x5x5 patch, and so on. Increasing this may give better results, but also seriously increases the computational time.

searcharea is the size of the spatial neighborhood in which to look for similar patches. This is similar to the patchsize in that 2 = 5x5x5 and 4=9x9x9.

beta is a smoothness parameter. Usually in the range 0-1. Larger beta means more smooth.

threshold is a parameter controlling the preselection of patches. Preselection makes sure to only include patches that have some similarity. The range is 0-1. The higher the more strict (fewer patches selected).

num_selected is the number of images to select from the library when looking for similar structures. Usually the higher the better. However, the improvement is asymptotic and the memory usage quickly rises with larger N.

For the command line options, you have:

-same_res which simply makes sure that the output has the same resolution no matter the conf-file.

-median applies a median filter on the probability map before propagation. This also smoothes the result and should be used when the library is not perfect (i.e. from another population than the image to segment).

-fill can always be used as this just morphologically fills any holes in the segmentation.

The rest are not really relevant for fine tuning. However, you may want to output the probability map when determining the best alpha.

How to get the best out of BEaST

The answer to this question is also from Dr. Eskildsen.

The best way to improve your results is to populate the library with images/masks from the same scanner as the images you are trying to segment. One way to do this is to run Beast with the default ICBM/ADNI images and then select the best masks among the results, possibly do some manual corrections, and put them into the library. Then run Beast again. I have used this bootstrapping method with success on several studies.

not so good cerebellums results

BEaST does provide improved brain extraction results in cortex, but I also noticed that it tends to clip into cerebellums in some of the subjects I was testing BEaST on. The following figure (Figure 2) shows an example: The upper panel is skull stripped image by AFNI's 3dSkullStrip, the lower panel then shows the image generated by BEaST, the red part is the difference between the two. The good chunk of tissue which I think is cerebellum is missing in image generated by BEaST.

Figure 2

Figure 2: BEaST clipping into cerebellum.

Dr. Eskildsen's reply on this issue is attached:

One of the motivations for Beast was to have a brain extraction method that removed the superior and transverse sinuses. I found that other tools included those structures in the brain mask and these are generally a nuisance when estimating cortical thickness (my main area of interest). As seen in your screen captures, the AFNI tool includes both the superior and transverse sinus in the mask. We took care removing those structures in the training library of Beast. Unfortunately, we focused on the cerebrum and perhaps neglected the cerebellum. Manual segmentation takes time and we had no use for the cerebellum in our analyses, so the library was constructed with varying accuracy in this part of the brain.

Still, I think the main differences you see are caused by the removal of the sinuses. However, the library should perhaps be improved if the cerebellum needs to be segmented with high accuracy.

IV. Other Resources about BEaST

If you are interested in BEaST and want to learn more about it, you might find the following resources helpful.

  • Webpage of BEaST: Link
  • Github page of BEaST: Link
  • Paper about BEaST: Link