T1 intensity normalization with FreeSurfer

In this post, I’ll demonstrate how to perform a minimal FreeSurfer based T1 intensity normalization pipeline. It’s very simple, but can be daunting if you’ve never used FreeSurfer before.

Tools and files used in this article:

T1.nii.gz is an HCP T1 weighted image and the version of FreeSurfer used is freesurfer-x86_64-unknown-linux-gnu-stable6-20170118.

If you already have FreeSurfer installed, then do the following (otherwise you scan skip ahead to docker/singularity):

wget https://justinblaber.org/downloads/articles/t1_normalization/T1.nii.gz
mri_convert T1.nii.gz T1.mgz
mri_nu_correct.mni --i T1.mgz --o T1_N3.mgz --n 2
mri_normalize -g 1 -mprage T1_N3.mgz T1_norm.mgz
mri_convert T1_norm.mgz T1_norm.nii.gz
 

The above code converts the T1 from nifti to mgz format, performs N3 normalization, performs intensity normalization, then converts back from mgz format to nifti.

If you have a FreeSurfer license and want to use a docker/singularity container instead, simply do the following instead:

mkdir INPUTS
mkdir OUTPUTS
wget https://justinblaber.org/downloads/articles/t1_normalization/T1.nii.gz -O INPUTS/T1.nii.gz
 

Then, for docker:

sudo docker run --rm \
-v $(pwd)/INPUTS/:/INPUTS/ \
-v $(pwd)/OUTPUTS:/OUTPUTS/ \
-v <path to license.txt>:/extra/freesurfer/license.txt \
--user $(id -u):$(id -g) \
justinblaber/t1_normalization:1.0.0
 

Or, for singularity:

singularity run -e \
-B INPUTS/:/INPUTS \
-B OUTPUTS/:/OUTPUTS \
-B <path to license.txt>:/extra/freesurfer/license.txt \
shub://justinblaber/t1_normalization_app:1.0.0
 

If everything runs successfully, the output should look like:

There’s an added benefit to the normalization step in that it attempts to set intensities to a predefined range:

  • white matter ~ 110
  • grey matter ~80
  • csf ~ 35

This makes it very convenient to scale the intensities when using T1s in neural networks. If you normalize a T1 with the above pipeline, then scale the intensities from [0, 110] to [-1, 1], the normalization should be consistent across all T1s.

Leave a Reply

Your email address will not be published. Required fields are marked *