Dealing with transforms in AFNI (Part 1)

AFNI’s main tool for dealing with transforms is cat_matvec, but in many cases you may not need to use it!  Everyone knows that transform matrices are confusing — I’ll do a post later on just covering them — but for now, I think we can all agree that it’s a relief anytime you don’t have to deal with figuring out transform matrices!

If you want to align your anatomic dataset and your EPI or DWI/DTI, you could use a range of tools like 3dWarpDrive (12-parameter affine), 3dAllineate (also 12-parameter but with more cost functions), or you could (and probably should) turn to the super-script  This script can do a lot!  It can do time shifting (sinc interp), motion correction, and volume co-registration with a host of available cost functions.  The added bonus of this script is that it can concatenate the transforms for you and reduce the number of times that your dataset gets warped (and thus interpolated, and therefore introduced more distortion/blur).  My “goto” call is something like this: -anat anat+orig -epi epi+orig -epi_base 0 -epi2anat

This will take care of Skull stripping the anatomic (and EPI), time shifting, motion correction, and volume registering the EPI to the anatomical.  I don’t mention it, but it will also take care of deobliquing the data.  If you use, it will do something similar but turn off time shifting and motion correction because these are handled in their own steps.

If you wanted to combine the EPI–>ANAT and ANAT–>MNI (or TT) transform, you could run @auto_tlrc first and feed the TLRC dataset to the script:

@auto_tlrc -base TT_N27+tlrc -input anat+orig -anat anat+orig -epi epi+orig -epi_base 0 -tlrc_apar anat+tlrc

In general, it’s usually a good idea to run @Align_Centers on your datasets first.  It’s not a deal-breaker, but can make your registration process less tedious.  Let’s assume our anatomic dataset is called anat+orig and our EPI is called epi+orig.

@Align_Centers -base anat+orig -dset epi+orig

This will create a new version of your EPI dataset called epi_shft+orig and introduce a transform called eli_shft.1D.  If we want to include this in our function call, we can add this transform to our call using the “-pre_matrix” flag.  However, since by default align_epi_anat moves the anatomic to match the EPI, and we’ve reversed that AND we’ve moved the EPI to match our anatomical, we need to invert the transform before we use it.  We do that via cat_matvec (I know I said it’s nice to avoid, but sometimes we can’t!)

cat_matvec epi_shft.1D -I > inverted_transform.1D
@auto_tlrc -base TT_N27+tlrc -input anat+orig -anat anat+orig -epi epi+orig -epi_base 0 \
-epi2anat \
-tlrc_apar anat+tlrc \
-pre_matrix inverted_transform.1D

Many of these concepts can be used for DWI/DTI data as well.  I’ve posted a bit on this before (and here), but I’ll try to update it again soon!

Comments are closed.