antsApplyTransforms Forward and inverse warps for warping images - Quantitative-Physiological-Imaging-Lab/documentation GitHub Wiki
In general, it is best to apply warps in a single step to avoid interpolation errors. This is an example of how to apply a number of warps to bring images between two spaces (moving -> fixed, fixed -> moving) in a single step.
Here, "firstlevel" refers to a (for example) within-subject design where an individual is co-registered across multiple timepoints; "secondlevel" would be the warps/affines for the co-registration between individuals in the group (i.e., that was used to generate a study-specific group template).
With ATNs, when using several transformations the transformations are pushed onto a transformation stack. The transformation that should be applied first has to be on top of the stack and therefore the last transformation pushed onto the stack. As all registrations that require rigid/affine transformations should compute this prior to non-linear warping, within each level this should be applied first.
Deforming the moving image to fixed space (multi-level registration (example for 2 levels)):
${ANTSPATH}antsApplyTransforms
-d 3
-i movingImage.nii.gz \ -r fixedImage.nii.gz
-t movingToFixed_secondLevel_1Warp.nii.gz
-t movingToFixed_secondLevel_0GenericAffine.mat
-t movingToFixed_firstLevel_1Warp.nii.gz
-t movingToFixed_firstLevel_0GenericAffine.mat
-o movingToFixedDeformed.nii.gz
Fixed image space deformed to moving space: (-n GenericLabel is used for interpolation of label indices)
${ANTSPATH}antsApplyTransforms
-d 3
-i fixedLabels.nii.gz
-r movingImage.nii.gz
-t [movingToFixed_firstLevel_0GenericAffine.mat, 1]
-t movingToFixed_firstLevel_1InverseWarp.nii.gz
-t [movingToFixed_secondLevel_0GenericAffine.mat, 1]
-t movingToFixed_secondLevel_1InverseWarp.nii.gz
-n GenericLabel[Linear]
-o labelsToMovingDeformed.nii.gz
The 1 after [*GenericAffine.mat,1] inverts the original affine matix -n --interpolation: Linear, NearestNeighbor, Multilabel, Gaussian (described in help function of antsApplyTransforms)