Neuroimaging Data Processing/Processing/Tools/AFNI

(Redirected from Neuroimaging Data Processing/AFNI)
Neuroimaging Data Processing/Processing/Tools



AFNI is a command line based tool, i.e. all the processing steps are defined in a script, using commands and methods built-in to afni, which is then run on the data. You can but don't have to put up your scripts from scratch, and (see below) are helpful tools to help you putting together your processing script. Afni does have a graphical viewer for images and graphs. Once you have installed AFNI (check tutorial below or [1]) and entered AFNI environment by typing AFNI, you can call this GUI by typing


to you terminal. It will try to find and open Afni or Nifti format datasets in your current folder and otherwise open on a default anatomical image. The tutorial mentioned below gives a good introduction to how you can use the viewer to inspect you data before, during and after processing.

What is


a command line program used to generate processing scripts (proc. scripts) for single subject analysis. Generated scripts are in tcsh syntax and written to be easily read and modified. Learn about the syntax you need here [2], where you find a full list of all the possible building blocks and options along with very helpful example scripts. You get the same output when typing (in AFNI environment): 

In the AFNI part of the implementation in each subsection of this wikibook there is some very basic information on respective commands you need for each step. Also the tutorial mentioned below is a good introduction to One thing I find helpful to know is how to includ non-default processing blocks in (if you read the help on it will become clearer what that means): you can include single blocks in their default position by


followed by the name of the block. If you want to include the processing blocks in a specific order use


followed by the blocks in their respective order.

What is


a graphical user interface to, for creating processing scripts and running the analysis. When starting with AFNI it might be easiest to create scripts using uber_subject and then explore the generated scripts and modulate them if you wish. However this tool is still rather new and might not be fully developed.

The uber_subject GUI is quite self-explanatory. You can find some help here [3] or just open and explore it using this command (given AFNI is installed and AFNI environment is active)
Afnis GUI

Data formats


AFNI can handle nifti files (nii and nii.gz). However, the native data format is .HEAD and .BRIK files (see Afni) and when using nifti files it seems there can be problems with the header information. To import dicom data into head/brik use the to3d command [4].

For example for functional data with TR 2300 ms, 257 volumes, 37 slices acquired in z direction and then in time (zt), in interleaved order (alt+z):

to3d -prefix OUTPUTFILE -time:zt 37 257 2300 alt+z INPUTFILES

INPUTFILES should be all dicoms, i.e. using a wildcard like data/func/run001/*.dcm and for anatomical

to3d -anat -prefix OUTPUTFILE INPUTFILES

Make sure in both cases that INPUTFILES refers to all dicoms, i.e. using a wildcard like path_to_data/*.dcm

Oblique data in AFNI


If you data was acquired oblique this information will be stored in the dicom header. Afni recognizes this and will complain. You should apply 3dWarp[5] to the oblique data (to both anatomical AND functional in case both are oblique). See also [6]

3dWarp -deoblique -prefix OUTPUTFILE INPUTFILE

Otherwise, probably due to different mosaic centers, your coregistration may end up looking something like this:

Coregistration can fail with oblique data

Documentation on the single commands

A tutorial with sample data is provided here:

The same tutorial, each step documented in a video:

This is a really helpful "what you need to know when you are absolutely new to AFNI":

And a ppt presentation which you might also find helpful as a start: