Get 2D image from 3D anatomy for overlay/jpg

Hi folks - I would like to take overlay stats form a functional analysis on anatomical data for each of hundreds of participants, and then select 1 2d image from the anat brik to save and print as .jpg. So - I will obviously use a shell, rather than the AFNI viewer to do this.

I have looked into a number of different 3d programs that will let me select one 2D image from a 3D anatomy BRIK, but I can’t seem to find one that does what I want. For example, I will overlay stats onto the anatomical BRIK for each participant and then select 1 medial 2d slice in the saggital plane to save as a .jpg.

Is there something I’m missing? Selecting sub-bricks from 3d+time briks is easy but I couldn’t see a method for selecting a single 2D image from the 3d anat brik.
I looked at 3dcalc, 3dcopy, 3dmerge, etc…

thanks a lot, mb



So, if I understand correctly, you want to make a JPG by:

  • picking one axial slice in an anatomical volume;
  • and overlaying statistical information?

You can do this by “driving” AFNI. See here for a host of things you can control from the command line:

The first example note there:

afni -com 'OPEN_WINDOW A.axialimage'       \
       -com 'SWITCH_UNDERLAY anat'           \
       -com 'SAVE_JPEG A.axialimage sss.jpg' \
       -com 'QUIT'                           \

… sounds like most of what you want. You can specify a selected slice, as well, with “SET_IJK” or one of the “SET*XYZ” options.


Hi mb,

You can SET the location based on DICOM coordinates,
SPM (LPI version), IJK indices or a voxel index. The XYZ
coordinates may be the most clear. Consider this command
from @DriveAfni:

plugout_drive -com 'SET_DICOM_XYZ A 0 20 40'              \
               -com 'SAVE_JPEG axialimage SavedAxiale.jpg'  \

The descriptions for commands like SET_IJK are in the
file README.driver (which should be in your abin).

Does that seem reasonable?

  • rick

thanks Rick & ptaylor - I’m going to check it out. Can’t say I’ve “driven” AFNI, before,so I’ll take her for a ride…

Thanks Rick & ptaylor - The drive plugin worked well and we were able to what we wanted. thanks again, mb

That is great, thanks for the update!

  • rick


I am struggling to print the overlay on the underlay.
Could you share your code to see what I might be doing wrong ?

My code :

afni   -noplugins -no_detach \
       -com "OPEN_WINDOW A.axialimage"  \
       -com "SWITCH_UNDERLAY anat_final.${subj}+tlrc"       \ 
       -com "SWITCH_OVERLAY stats.PW3.${subj}+tlrc 6 7"           \
       -com "SEE_OVERLAY +"  \
       -com "SET_THRESHNEW A.axialimage 0.01 p" \
       -com "SAVE_JPEG A.axialimage test1.jpg" \
       -com QUIT

Anybody would know what i'm doing wrong ?


Nowadays, I would say by far the easier way to go would be to use @chauffeur_afni, which wraps around the driving functionality in the GUI (as well as environment-variable-based features). You can make montages, control opacity and overlay thresholding, and so very much more. This program is the main workhorse behind the QC HTML (APQC HTML):

By default, sets of axial, coronal and sagittal images are output; you can let the program evenly space slices across the full FOV or mask, or you can specify your own central coordinate and delta_slice number.

Examples are provided in this tutorial, including showing effect estimates plus statistic values as overlay and threshold volumes, respectively:

And for such images, please also consider the benefits of transparent thresholding, to helpfully show more data:

Please ping back if you have any further questions about making these images.


Wow, this is wonderful.
It is difficult through search engins to find proper script and functionalities.

Thanks for the help :D


Sure thing. And indeed, sometimes asking on the Message Board is the speediest way to find some functionality.