Image and Volume Registration with AFNI
Goal: bring images collected with different methods and at different times into alignment
Facilitates comparison of data on a voxel-by-voxel basis
Functional time series data will be less contaminated by artifacts due to subject movement
Can compare results across scanning sessions once images are properly registered
Most (all?) image registration methods now in use do pairwise aligment:
Given a base image J(x) and target image I(x), find a geometrical transformation T[x] so that I(T[x])ÅJ(x)
 T[x] will depend on some parameters
Goal is to find the parameters that make the transformed I a Ôbest fitÕ to J
To register an entire time series, each volume In(x) is aligned to J(x) with its own transformation Tn[x], for n=0, 1, É
Result is time series In(Tn[x]) for n=0, 1, É
User must choose base image J(x)

"Most image registration methods make..."
Most image registration methods make 3 algorithmic choices:
How to measure mismatch E (for error) between I(T[x]) and J(x)?
How to adjust parameters of T[x] to minimize E?
How to interpolate I(T[x]) to the J(x) grid?
So can compare voxel intensities directly
Existing AFNI programs match images by grayscale (intensity) values
 E = (weighted) sum of squares differences = Sx w(x) á {I(T[x]) - J(x)}2
Only useful for registering Ôlike imagesÕ:
SPGRSPGR, EPIEPI, but not SPGREPI
Parameters in T[x] are adjusted by Ògradient descentÓ
Several interpolation methods are available:
Default method is Fourier interpolation
Polynomials of order 1, 3, 5, 7 (linear, cubic, quintic, and heptic)
Alternative method would be to match features computed from grayscale images:
Brain outline
Edges (places where image intensity changes abruptly in 1-2 pixels)
Such techniques can be used to match SPGREPI volumes
Program 3dAnatNudge can estimate SPGREPI translations
But not rotations or warping

"AFNI program 3dvolreg is for..."
AFNI program 3dvolreg is for aligning 3D volumes
 T[x] has 6 parameters:
Shifts along x-, y-, and z-axes; Rotations about x-, y-, and z-axes
Generically useful for intra- and inter-session alignment
Motions that occur within a single TR (2-3 s) cannot be corrected this way, since method assumes a rigid movement of the entire volume
AFNI program 2dImReg is for aligning 2D slices
 T[x] has 3 parameters for each slice in volume:
Shift along x-, y-axes; Rotation about z-axis
Useful for sagittal EPI scans where dominant subject movement is ÔnoddingÕ motion that my be faster than TR
It is possible and sometimes even useful to run 2dImReg to clean up nodding motion, followed by 3dvolreg to deal with out-of-slice motion
Hybrid Ôslice-into-volumeÕ registration:
Put each separate 2D image slice into the target volume with its own 6 movement parameters (3 out-of-plane as well as 3 in-plane)
Has been attempted by some AFNI users but the results are not wildly better than volume registration; method often fails on slices near edge of brain
More work is needed (i.e., send money)

"Intra-session registration:"
Intra-session registration:
3dvolreg -base 4 -heptic -clipit -zpad 4 \
  -prefix fred1_epi_vr \
  -dfile fred1_vr_dfile  \
  fred1_epi+orig
-base 4 Þ Selects sub-brick #4 of dataset fred1_epi+orig as base image J(x)
-heptic Þ Use 7th order polynomial interpolation (my personal favorite)
-clipit Þ Clip off negative voxels to zero
Negative voxels are artifacts of high-order interpolation methods
-zpad 4 Þ Pad each target image, I(x), with layers of zero voxels 4 deep on each face prior to shift/rotation, then strip them off afterwards
Zero padding is particularly desireable for -Fourier interpolation
Is also good for polynomial methods, since if there are large rotations, some data may get ÔlostÕ when no zero padding if used (due to 4-way shift algorithm used for fast rotation)
-prefix fred1_epi_vr Þ Save output dataset into a new dataset with the given prefix name (e.g., fred1_epi_vr+orig)
-dfile fred1_vr_dfile Þ Save estimated movement parameters into a 1D (i.e., text) file with the given name
Can be plotted with command
1dplot -volreg -dx 5 -xlabel Time Ôfred1_vr_dfile[1..6]Õ

"Can now register second dataset..."
Can now register second dataset from same session:
3dvolreg -base Ôfred1_epi+orig[4]Õ -heptic -clipit -zpad 4 \
             -prefix fred2_epi_vr -dfile fred2_vr_dfile     \
      fred2_epi+orig
Note base is from different dataset (fred1_epi+orig) than input (fred2_epi+orig)
Aligning all EPI volumes from session to EPI closest in time to SPGR
1dplot -volreg -dx 5 -xlabel Time Ôfred2_vr_dfile[1..6]Õ gives:

"Examination of time series fred2..."
Examination of time series fred2_epi+orig and fred2_epi_vr_+orig shows that head movement up and down happened within about 1 TR interval
Assumption of rigid motion of 3D volumes is not good for this case
Can do 2D slice-wise registration with command
2dImReg -input fred2_epi+orig \
-basefile fred1_epi+orig \
-base 4 -prefix fred2_epi_2Dreg

"Intra-subject,"
Intra-subject, inter-session registration (for multi-day studies on same subject)
Longitudinal or learning studies; re-use of cortical surface models
Transformation between sessions is calculated by registering high-resolution anatomicals from each session

"Anatomical coverage differs"
Anatomical coverage differs

"Another problem:"
Another problem: rotation occurs around center of individual datasets

"Solutions to these problems:"
Solutions to these problems:
Add appropriate shift to E2 on top of rotation
Allow for xyz shifts between days (E1-E2), and center shifts between EPI and SPGR (E1-S1 and E2-S2)
Pad EPI datasets with extra slices of zeros so that aligned datasets can fully contain all data from all sessions
Zero padding of a dataset can be done in to3d (at dataset creation time), or later using 3dZeropad
3dvolreg and 3drotate can zero pad to make the output match a Ògrid parentÓ dataset in size and location

"Recipe for intra-subject S2..."
Recipe for intra-subject S2-to-S1 transformation:
Compute S2-to-S1 transformation:
3dvolreg -twopass -clipit -zpad 4 -base S1+orig \         -prefix S2reg  S2+orig
Rotation/shift parameters are saved in S2reg+orig.HEAD
If not done before (e.g., in to3d), zero pad E1 datasets:
3dZeropad -z 4 -prefix E1pad  E1+orig
Register E1 datasets within the session:
3dvolreg -clipit -base ÔE1pad+orig[4]Õ -prefix E1reg \   E1pad+orig
Register E2 datasets within the session, at the same time executing larger rotation/shift to session 1 coordinates that were saved in S2reg+orig.HEAD:
3dvolreg -clipit -base ÔE2+orig[4]Õ \    -rotparent S2reg+orig      \
  -gridparent E1reg+orig \
  -prefix E2reg  E2reg+orig
-rotparent tells where the inter-session transformation comes from
-gridparent defines the output grid location/size of new dataset
Output dataset will be shifted and zero padded as needed to lie on top of E1reg+orig

"Recipe above does not address..."
Recipe above does not address problem of having different slice thickness (EPI and/or SPGR) in different sessions
Best solution: pay attention when you are scanning, and always use the same slice thickness for the same type of image
OK solution: use 3dZregrid to linearly interpolate datasets to a new slice thickness
Recipe above does not address issues of slice-dependent time offsets stored in data header from to3d (e.g., Ôalt+zÕ)
After interpolation to a rotated grid, voxel values can no longer be said to come from a particular time offset, since data from different slices will have been combined
Before doing this spatial interpolation, it makes sense to time-shift dataset to a common temporal origin
Time shifting can be done with program 3dTshift
Or by using the -tshift option in 3dvolreg, which first does the time shift to a common temporal origin, then does the 3D spatial registration
Further reading at the AFNI web site
File README.registration (plain text) has more detailed instructions and explanations about usage of 3dvolreg
File regnotes.pdf has some background information on issues and methods used in FMRI registration packages