User Tools

Site Tools


Freesurfer Guide

How to run Freesurfer on Golgi

The tutorial below will refer to running Freesurfer to create the segmentation images, the inflated images, the parcellation images, and all of the other supplemental files it creates.

Create your data directories

Under your data folder (/data/users/yourusername/) create a “freesurfer” folder. Under this folder, create two subfolders, “subjects” and “sessions”. You need the “subjects” directory for 3-D surface reconstruction and segmentation; the “sessions” directory will be needed later if you use FreeSurfer tools for functional analysis.

Directory Tree: 
  - freesurfer 
    -- subjects 
    -- sessions 

Set up your environment

  • The scripts to run Freesurfer use the tcsh/csh shells.
  • Change to tcsh shell by typing “tcsh” at the Golgi command prompt.
  • You'll need to add the following lines to your .tcshrc file in your home directory (create this file if it doesn't exist), or you could just type these commands every time you want to run Freesurfer:
set SUBJECTS_DIR = /data/users/$user/freesurfer/subjects   
set FUNCTIONALS_DIR = /data/users/$user/freesurfer/sessions   
source /usr/local/packages/freesurfer-dev2-0-0/SetUpFreeSurfer.csh 

Upload/copy your data to the freesurfer directory

  • The Freesurfer analysis only runs on T1 weighted data.
  • The data must be in DICOM format to run properly (all anatomical data from the transfer daemon is in DICOM format).
  • Make a directory under /data/users/yourusername/freesurfer for one subject's T1 data.
  • Upload or copy a T1-weighted series directory into this subject's folder.
Directory Tree: 
  - freesurfer 
    -- SubjectNumber1 
       --- series500 
           ---- All .dcm files of T1-weighted data here 
    -- subjects 
    -- sessions 

Run Freesurfer

  • The program “runfreesurfer”, written by Jim Voyvodic, will run all of the Freesurfer analysis.
  • “runfreesurfer” calls the Freesurfer command “recon-all” with the parameters “-autorecon1”, “-autorecon2” and “-autorecon3”.
  • “runfreesurfer” is located in the following folder:
  • Change to the tcsh or csh shell (type “tcsh” at the command prompt).
  • Call “runfreesurfer” from the subject directory with two input arguments. The 1st argument is the subject identifier name, and the 2nd argument is the folder name of the T1-weighted dicom data. The subject name is usually a short text string; it will be used to label this brain and must not match any other FreeSurfer brain.
Example from the directory tree above: 
> runfreesurfer Subject1 series500 
  • You may see some warning messages appear, which you can ignore if the process keeps running. If it gets past the first hour without stopping it will probably run through okay.
  • The full operation could take as much as 3 days to complete. Since this is such a resource intensive operation, please limit to running two subjects at a time, at most. Golgi does have multiple processors, but other users might notice a lag if many Freesurfer jobs are running.
  • There should be a file called “recon.log” created in the subject directory. To determine if Freesurfer is finished, you can run the following command and see if there are three instances of “recon-all finished without error” returned.
> grep finished recon.log 

Visualization of FreeSurfer results

  • To see the results you can use FreeSurfer's “tksurfer” and “tkmedit” tools, or you can use “fScan” developed at BIAC. For help on using fScan, go to:

Using fScan for visualizing FreeSurfer

How do I get the data back into the original space?

The volume output (aseg.mgz, aparc+aseg.mgz, etc…) of Freesurfer will probably be in a different image space than your original data (this output is always 256x256x256, 1mm^3, and in coronal orientation). If you'd like to get this data back into the same space as your orignal data, you can use the freesurfer command “mri_convert” to do this:

mri_convert -rl rawavg.mgz -rt nearest aseg.mgz aseg2raw.nii.gz 

where the -rl flag means “reslice like” (basically the “target”; the file “rawavg.mgz” in the mri/ folder is in the original image space) and -rt is the resample type (interpolate, weighted, nearest, sinc or cubic; default is interpolate). For label files like aseg.mgz and aparc+aseg.mgz, you'll want to use “nearest” so you don't get fractional values.

biac/freesurfergolgi.txt · Last modified: 2014/08/04 16:03 (external edit)