Author: Mert R Sabuncu, © 2010-2011 email:
A.A. Martinos Center for Biomedical Imaging, Massachusetts General Hospital, Harvard Medical School
Computer Science and Artificial Intelligence Lab, Massachusetts Institute of Technology (MIT)

This is a Matlab toolbox for performing pairwise and groupwise image registration (diffeomorphic) and label fusion style segmentation.
For details on the methods, please refer to the following papers:

[1] A Generative Model for Image Segmentation Based on Label Fusion, MR Sabuncu, BTT Yeo, K Van Leemput, P Golland and B Fischl. IEEE Transactions on Medical Imaging, vol. 29, no. 10, 2010. [pdf]
[2] Asymmetric Image-Template Registration, MR Sabuncu, BTT Yeo, T Vercauteren, K Van Leemput and P Golland, Proceedings of the International Conference on Medical Image Computing and Computer Assisted Intervention (MICCAI), LNCS 5761, p. 565-573, 2009.


CURRENT VERSION NOTES: This is version 1.0 — the very first public release version. Inevitably, there are going to be bugs/errors in the code. I will try my best to fix them as I become aware of them. Updates will be posted as code fixes become available. Please email: if you notice any bugs in the code or if you have any problems.

You will need ITK, CMake, and Matlab.
(1) Download latest version of ITK from (We tested on v3.20)
(2) Download and install CMake on your machine (
(3) Use CMake to generate ITK make files (or equivalent). You can follow the instructions on the ITK website. Make sure to have BUILD_SHARED_LIBS, ITK_PATENTED, and ITK_USE_REVIEW checked in CMake before generating the Make file.
(4) Compile/Build ITK.
(5) Launch Matlab in the BrainFuseLab directory.
(6) Setup mex, if this is the first time you’re using mex. (For help:
(7) Edit compile_mex.m in the root directory of the toolbox. Change where ITK_DIR points to.
(8) Edit ./diffeomorphic_registration/compile_example.m. This will require some work — you will need to find the dynamic libraries (identify the extension for your system+compiler) and their location.
(9) In the root directory, call compile_mex.m — this compiles all necessary mex files. Hopefully, everything will compile fine.
(10) If you’re on a unix-based machine — go into ./diffeomorphic_registration — edit the compile_mex_unix.csh so that ITK_DIR and Matlab directories point to the right location. And then type the following command lines.
> rm CMakeCache.txt
> source compile_mex_unix.csh
> make

In Matlab, in the BrainFuseLabe_release folder: type add_BFL_paths.m
There are several *DEMO.m files that demonstrate the capabilities of the tools. Go ahead and explore them!

For questions/remarks/feedback/bugs: email


Label Fusion is an automatic segmentation method that utilizes a collection of training images (pairs of images and corresponding label maps). Rather than summarizing the training data in a parametric atlas, label fusion employs the entire dataset. A given new image (which is to be automatically segmented), is registered with each training subject in a pairwise fashion (using the diffeomorphic registration tool that is available in this package). Then, the manual labels are propagated to novel image coordinates. Label fusion simply reduces to a local weighted averaging procedure, where training subjects that are locally more similar (in terms of image intensity) to the novel subject get more weight.

In this toolbox, we present label fusion implementation that is suitable for automatically parcellating structural brain MRI scans. We have optimized the implementation to work with pre-processed (ie, skull-stripped, intensity-normalized, and re-sampled to 1mm^3 grid) images, such as “norm.mgz”, which is generated by FreeSurfer ( in the early stages of the econ-all pipeline.

As training data, we provide 18 manually labeled images, which are available through:

More details about the data can be found in the README.txt file located in ./data/

These MRI scans were pre-processed with FreeSurfer to obtain corresponding norm.mgz files. We then transferred the manual labels over to the norm.mgz space.
These pairs of files, made available for 18 subjects in this toolbox, are used as training data for the example label fusion implementation here.


The diffeomorphic registration code is based on Tom Vercauteren‘s Demons-based diffeomorphic registration implementation.

The affine registration module makes use of a publicly-available bounded fminsearch implementation due to John D’Errico:

Label fusion employs an efficient signed distance transform implementation due to Gabriel Peyre: