antsApplyTransforms.Rd
Apply a transform list to map an image from one domain to another. In image registration, one computes mappings between (usually) pairs of images. These transforms are often a sequence of increasingly complex maps, e.g. from translation, to rigid, to affine to deformation. The list of such transforms is passed to this function to interpolate one image domain into the next image domain, as below. The order matters strongly and the user is advised to familiarize with the standards established in examples.
antsApplyTransforms(
fixed,
moving,
transformlist = "",
interpolator = c("linear", "nearestNeighbor", "multiLabel", "gaussian", "bSpline",
"cosineWindowedSinc", "welchWindowedSinc", "hammingWindowedSinc",
"lanczosWindowedSinc", "genericLabel"),
imagetype = 0,
whichtoinvert = NA,
compose = NA,
verbose = FALSE,
...
)
fixed image defining domain into which the moving image is transformed.
moving image to be mapped to fixed space.
character vector of transforms generated by antsRegistration where each transform is a filename.
Choice of interpolator. Supports partial matching.
linear
nearestNeighbor
multiLabel for label images but genericlabel is preferred
gaussian
bSpline
cosineWindowedSinc
welchWindowedSinc
hammingWindowedSinc
lanczosWindowedSinc
genericLabel use this for label images
choose 0/1/2/3 mapping to scalar/vector/tensor/time-series
optional list of booleans, same length as transforms. whichtoinvert[i] is TRUE if transformlist[i] is a matrix, and the matrix should be inverted. If transformlist[i] is a warp field, whichtoinvert[i] must be FALSE.
If the transform list is a matrix followed by a warp field, whichtoinvert defaults to c(TRUE,FALSE). Otherwise it defaults to rep(FALSE, length(transformlist)).
if it is a character string pointing to a valid file location, this will force the function to return a composite transformation filename.
print command and run verbose application of transform.
extra parameters
an antsImage or transformation filename is output. 1 – Failure
# will give the full form of help
antsApplyTransforms("-h")
#> NULL
# see antsRegistration
# example 1 - simplified
fixed <- ri(1)
moving <- ri(2)
fixed <- resampleImage(fixed, c(64, 64), 1, 0)
moving <- resampleImage(moving, c(68, 68), 1, 0)
mytx <- antsRegistration(
fixed = fixed, moving = moving,
typeofTransform = "SyN", verbose = TRUE, printArgs = TRUE
)
#> antsRegistration -d 2 -r [0x600002a9d340,0x600002a9f460,1] -m mattes[0x600002a9d340,0x600002a9f460,1,32,regular,0.2] -t Affine[0.25] -c 2100x1200x1200x0 -s 3x2x1x0 -f 4x2x2x1 -x [NA,NA] -m mattes[0x600002a9d340,0x600002a9f460,1,32] -t SyN[0.2,3,0] -c [ 40x20x0 ,1e-7,8] -s 2x1x0 -f 4x2x1 -u 0 -z 1 -o [/tmp//Rtmpx3PKqM/filebbf73809607,0x600002a9f8b0,0x600002a9f2e0] -x [NA,NA] --float 1 --random-seed 1 --write-composite-transform 0 -v 1
mywarpedimage <- antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = mytx$fwdtransforms
)
testthat::expect_true(antsImagePhysicalSpaceConsistency(mywarpedimage, fixed))
invwarped_image <- antsApplyTransforms(
fixed = moving, moving = fixed,
transformlist = mytx$invtransforms
)
testthat::expect_true(antsImagePhysicalSpaceConsistency(invwarped_image, moving))
# full access via listing the inputs in standard ANTs format
res1 <- antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = mytx$fwdtransforms[2],
whichtoinvert = 1, verbose = TRUE
)
#> [1] "-d"
#> [2] "2"
#> [3] "-i"
#> [4] "<pointer: 0x600002a9ef60>"
#> [5] "-o"
#> [6] "<pointer: 0x600002ab51f0>"
#> [7] "-r"
#> [8] "<pointer: 0x600002ab6920>"
#> [9] "-n"
#> [10] "linear"
#> [11] "-t"
#> [12] "[/tmp//Rtmpx3PKqM/filebbf738096070GenericAffine.mat,1]"
cfile <- antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = mytx$fwdtransforms,
compose = tempfile()
)
cimg <- antsImageRead(cfile)
cout <- antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = cimg
)
#> Warning: transformlist is an antsImage, creating a temporary file
testthat::expect_error(
antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = cimg, whichtoinvert = 1
), "nnot invert transform"
)
#> Warning: transformlist is an antsImage, creating a temporary file
testthat::expect_error(
antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = cimg, whichtoinvert = c(1, 2)
), "same length"
)
#> Warning: transformlist is an antsImage, creating a temporary file
testthat::expect_error(antsApplyTransforms(
fixed = fixed, moving = moving,
transformlist = ""
))