Creating Volume ROIs in AFNI

For those keeping track at home, an ROI involves selecting a section of the brain (or subset of voxels) that you have some interest in.  The ROI can be a geometric shape or drawn by hand.  It can be defined by anatomical markers or by functional activation or really by anything you want.

Screen Shot 2013-07-25 at 7.12.59 AM

AFNI has a number of ways of creating Regions of Interest (ROIs), I review some of the more common ways of creating an ROI below.  I will cover creating ROIs on the surface for use with SUMA in a later post!

Draw an ROI by hand

  1. Open AFNI Viewer
  2. Set Underlay as Subject’s Anatomical (anat_final if you use
  3. Right Click on Anatomical image in any view (axial, sagittal, coronal)
  4. Select Draw ROI Plugin (the window below will appear)
  5. Set your dataset for copying as the anatomical
  6. Select a mode for drawing
    1. Filled Curve lets you click draw freehand style
    2. Sphere and Circle options with size options
    3. Specify a value – if you have more than one ROI, give them different values!
    4. Third Mouse Click on the image where you want the ROI to be (or draw freehand while holding middle click)
    5. When complete, press Save.
  7. Down sample the mask to the size of your stats or functional datasets via 3dresample or 3dfractionize!
  8. Extract values with 3dmaskave, 3dmaskdump, 3dROIstats, etc…

Screen Shot 2013-07-24 at 4.52.38 PM

Create ROI mathematically using coordinate systems

You can create an ROI using 3dcalc.  Example #7 in the help of 3dcalc shows that the following code can be used to create a sphere ROI with a radius of 3 with origin (center) at x=20, y=30, z=70.

3dcalc -a anat+tlrc \
-expr 'step(9-(x-20)*(x-20)-(y-30)*(y-30)-(z-70)*(z-70))' \
-prefix ball

You will need to down sample the ROI for your functional or stats dataset using 3dfractionize or 3dresample.  Then you can extract values with 3dmaskave, 3dmaskdump, 3dROIstats, etc…  You can also draw other shapes fairly easily using 3dcalc.

If you just wish to create a sphere, you can use the -srad option in 3dUndump.  3dUndump also allows you to specify the values of specific voxels from either the terminal or a 1D file or with a combination of 3dmaskdump and 3dUndump (I like to do things with AWK or Python in the middle of the dump and Undump).

Create ROI from functional activations

  1. Load underlay as your subjects anatomical (anat_final if you use
  2. Load overlay as your subjects stats file (REML if you like)
  3. Set OLay and Thr sub-briks to your coefficient and t-stat (or t-stat for both if you’re inclined!)
  4. Set p-value to a value you feel is appropriate
  5. Turn on Clustering using the Clusterize button
  6. Specify a Cluster size (can use a value you like or one from 3dClustSim)
  7. Click Set and then Click “Rpt” for “Report”
  8. See a window listing the clusters that meet threshold and your criteria for size.
    1. Play around with Jump, Flash, Plot (need AUX dataset set), and Save
    2. Notice that list of clusters changes as you change the p-value using your t-stat slider!
  9. To Save Clusters press “SaveMsk”, see a 3dClust command presented in the terminal.
  10. Notice automatically created Clust_mask+tlrc.HEAD/BRIK
  11. Each cluster saved with a separate value 1 to X, where X is the max number.
  12. Extract values for 2nd largest cluster via: 3dmaskave -mask Clust_mask+tlrc.HEAD'<2>’ mydataset+tlrc.HEAD
  13. Extract all/other values with 3dmaskave, 3dmaskdump, 3dROIstats, etc…


Create ROI based on Atlas defined anatomical region

  1. Identify which Atlas you wish to use, full list seen in: whereami -show_atlases
  2. Identify which regions are available in the Atlas you have chosen: whereami -show_atlas_code -atlas CA_N27_ML
  3. Create a mask for region of choice: whereami -mask_atlas_region CA_N27_ML:left:middle_frontal_gyrus -prefix left_mfg
  4. Repeat with other regions if necessary
  5. OPTIONAL: combine into single mask: 3dcalc -a left_mfg+tlrc -b right_mfg+tlrc -prefix mfg_lr -expr ‘1*a + 2*b’
  6. Down sample the ROI to your functional or stats datasets with 3dresample or 3dfractionize
  7. Extract values with 3dmaskave, 3dmaskdump, 3dROIstats, etc…

Create ROI based on individual subject Freesurfer Segmentation

  1. Run freesurfer segmentation for your participant
  2. Navigate to that folder in Terminal/Shell and run @SUMA_Make_Spec_FS
  3. cd into the SUMA directory
    1. If you launch AFNI, set underlay as brain.nii and overlay as aparc+aseg_rank or aseg_rank for same visualization as below!
  4. Identify region of interest in one of the following NIML label tables
  5. Create ROI: 3dcalc -a aseg_rank.nii'<15>’ -prefix L_AMG.nii.gz -expr ‘step(a)’
    1. Creates subject specific ROI in Left Amygdala
  6. Make sure this is aligned the same as your anat_final dataset
  7. Down sample to your functional or stats dataset using 3dresample or 3dfractionize
  8. Extract values with 3dmaskave, 3dmaskdump, 3dROIstats, etc…



Are you tired yet?  As you can see there are a significant number of ways to make ROIs in AFNI.  I will cover the options for getting data out of ROIs in a later post.

Comments are closed.