Creating automated snapshots of fMRI activation

There are plenty of times when you want to create snapshot images at a particular threshold so that you can quickly view the activation profiles of all participants within a given study.  AFNI offers this functionality through a plugout_drive application where you can tell AFNI to change overlay, underlay, threshold, etc and even save the screenshots to disk.  You can then automate the process if you like by encapsulating everything in a bash/ruby/python script.

Below is a simple example where we have several NIFTI files in a folder, along with the template image TT_N27.nii (originally TT_N27+tlrc).  Call this script with the arguments of the statistical maps that you would like to open as overlays.  AFNI will then open each overlay and take a snapshot with a p-value of 0.01.  You can of course modify the p-value in the script as well as change the spacing of slices, etc.  You could also have it go into subfolders by using bash to manage your directories however you like.

 

#!/bin/bash
echo "Beginning snapshots";
mkdir snapshots
afni -yesplugouts &
sleep 4
plugout_drive -com "OPEN_WINDOW A.axialimage mont=6x6:3 geom=600x600+800+600" \
 -com "CLOSE_WINDOW A.sagittalimage" \
 -com "SWITCH_UNDERLAY TT_N27.nii.gz" \
 -quit
 for aMap in $@
 do
 outputName=`basename $aMap .nii`
 plugout_drive -com "SET_FUNC_RANGE A.10" \
 -com "SWITCH_OVERLAY $aMap" \
 -com "SET_DICOM_XYZ A 0 16 23" \
 -com "SET_SUBBRICKS A -1 1 1" \
 -com "SET_THRESHNEW A .01 *p" \
 -com "SAVE_JPEG A.axialimage snapshots/${outputName}_snapshot.jpg" \
 -quit
 done
plugout_drive -com "QUIT"
Comments are closed.