Necessary Tools

Freesurfer, FSL, and MRtrix3 are the three main neuroimaging and registration software that you need to run a systematic data pipeline of neuroimaging data (i.e. CT, MRI, DWI).

  1. Freesurfer

FreeSurfer is a software package for the analysis and visualization of structural and functional neuroimaging data from cross-sectional or longitudinal studies.

  1. FSL

FSL is a comprehensive library of analysis tools for FMRI, MRI and DTI brain imaging data.

  1. MRtrix3

MRtrix3 is primarily intended to be used for the analysis of diffusion MRI data. In addition, at its fundamental level it is designed as a general-purpose library for the analysis of any type of MRI data.

Data Processing Pipeline:

1. DWI Processing

  • Process diffusion imaging data, by denoising the data, then preprocessing it, then applying bias correction and then estimating the response function.


    dwipreproc -rpe_none AP DTI_30_average-2_denoise.mif

    dwibiascorrect –fsl

    dwi2response tournier

    dwi2fod csd DTI_30_average-2_denoise_preproc_biascorrected.mif DTI_30_average-2_denoise_preproc_biascorrected_response.txt DTI_30_average-2_denoise_preproc_biascorrected_fod.mif

2. T1 MRI Processing

3. (Optional) CT Processing

4. Connectome Generation


Freesurfer is a tool built for rendering 3D brains using MRI and Ct scans. FSL is a tool for coregistration and image analysis. Download both online:

Common Definitions:

  1. Registration: to find a common coordinate system for the input data sets


First, let's walk through how implementation occurs.

1. Set Up

First you will want to download FreeSurfer from the following website: Linux:

export FREESURFER_HOME=/usr/local/freesurfer

## tcsh
setenv FREESURFER_HOME /usr/local/freesurfer
source $FREESURFER_HOME/SetUpFreeSurfer.csh


export FREESURFER_HOME=/Applications/freesurfer

Run those commands within your terminal, or add them to ~/.bashrc file to have access to all the command line tools for freeview.

You will need to setup your own directory where you will hold all your subject data.

export SUBJECTS_DIR=<path to subject data>

This will be where you store say patient's MRI/CT scans that you will use to reconstruct the brain.

2. Running Through T1-Weighted MRI Images

First you want to set your current Subjects directory to where you are working with the raw say .dcm data.


There may be an issue where you can't run the functions with your .dcm files. I have no idea why this occurs, but an easy fix is to externally run a dicom to nii converter and pass this type of file instead. Here is a link to a matlab converter that can do this:

There are also other resources online.

Afterwards, you can run the following command(s):

recon-all -i <data>.nii -s <subject_name> -autorecon1
recon-all -i <data>.nii -s <subject_name> -all

This will take a long time! So be prepared to run this on a compute engine that has time.

3. Running Through CT Images

flirt -in patient_ct.nii -ref patient_mri.nii -omat patient_omat.mat -out patient_registered.nii.gz

This command will coregister the CT data onto the domain of the MRI data and provide a coregistration for you to look at where certain contacts of electrodes are. You can also view in Freeview the different cuts of the brain using either CT, or MRI.