View source: R/antsRegistration.R
antsRegistration | R Documentation |
Register a pair of images either through the full or simplified interface to the ANTs registration method.
antsRegistration(
fixed = NULL,
moving = NULL,
typeofTransform = "SyN",
initialTransform = NA,
outprefix = NULL,
mask = NULL,
movingMask = NULL,
maskAllStages = FALSE,
gradStep = 0.2,
flowSigma = 3,
totalSigma = 0,
affMetric = "mattes",
affSampling = 32,
synMetric = "mattes",
synSampling = 32,
affIterations,
regIterations = c(40, 20, 0),
multivariateExtras,
restrictTransformation,
writeCompositeTransform = FALSE,
randomSeed,
samplingPercentage = 0.2,
verbose = FALSE,
printArgs = FALSE,
...
)
fixed |
fixed image to which we register the moving image. |
moving |
moving image to be mapped to fixed space. |
typeofTransform |
A linear or non-linear registration type. Mutual
information metric by default. See |
initialTransform |
either a single transform file name, a vector of transform file names, or a single antsTransform object. If NA, an initial translation aligns the center of mass of the moving image to that of the fixed image, unless the transform is "deformable only", in which case the intial transform is 'Identity'. |
outprefix |
output will be named with this prefix. |
mask |
Registration metric mask in the fixed image space. |
movingMask |
Registration metric mask in the moving image space. |
maskAllStages |
If true, apply metric mask(s) to all registration stages, instead of just the final stage. |
gradStep |
gradient step size (not for all tx) |
flowSigma |
smoothing for update field |
totalSigma |
smoothing for total field |
affMetric |
the metric for the affine part (GC, mattes, meansquares) |
affSampling |
the sampling parameter for the affine metric |
synMetric |
the metric for the syn part (CC, mattes, meansquares, demons) |
synSampling |
the nbins or radius parameter for the syn metric |
affIterations |
vector of iterations for low-dimensional registration. we will set the smoothing and multi-resolution parameters based on the length of this vector. |
regIterations |
vector of iterations for syn. we will set the smoothing and multi-resolution parameters based on the length of this vector. |
multivariateExtras |
list of additional images and metrics which will
trigger the use of multiple metrics in the registration process
in the deformable stage. Multivariate metrics needs 5 entries:
name of metric, fixed, moving, weight, samplingParam.
the list should be of the form
|
restrictTransformation |
This option allows the user to restrict the
optimization of the displacement field, translation, rigid or affine
transform on a per-component basis. For example, if one wants to limit
the deformation or rotation of 3-D volume to the first two dimensions,
this is possible by specifying a weight vector of |
writeCompositeTransform |
if |
randomSeed |
integer random seed. combine with setting ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS environment variable to limit the impact of numerical differences. |
samplingPercentage |
value between zero and one that allows the percentage of points sampled to be controlled in low-dimensional metric estimation. |
verbose |
request verbose output (useful for debugging) |
printArgs |
print raw command line (useful for debugging) |
... |
additional options see antsRegistration in ANTs |
typeofTransform can be one of:
Translation transformation.
Rigid transformation: Only rotation and translation.
Similarity transformation: scaling, rotation and translation.
Rigid transformation: Only rotation and translation. May be useful for quick visualization fixes.'
Rigid transformation: Only rotation and translation. Employs dense sampling during metric estimation.'
Rigid transformation: Parameters typical for BOLD to BOLD intrasubject registration'.'
Affine transformation: Rigid + scaling.
Fast version of Affine
.
Affine transformation: Parameters typical for BOLD to BOLD intrasubject registration'.'
translation, rigid, similarity, affine (twice). please set
regIterations
if using this option. this would be used in cases
where you want a really high quality affine mapping (perhaps with mask).
Symmetric normalization: Affine + deformable transformation.
Uses synMetric
as optimization metric and elastic regularization.
Symmetric normalization: Affine + deformable transformation.
Uses synMetric
as optimization metric.
Symmetric normalization: Rigid + Affine + deformable transformation.
Uses synMetric
as optimization metric.
Symmetric normalization: no initial transformation.
Uses synMetric
as optimization metric. Assumes images are
aligned by an inital transformation. Can be useful if you want to run
an unmasked affine followed by masked deformable registration.
Elastic normalization: no initial transformation.
SyN, but with cross-correlation as the metric.
Note, the default or chosen parameters will be replaced with
synMetric="CC", synSampling=4, synits="2100x1200x1200x20",
smoothingsigmas="3x2x1x0", shrinkfactors="4x3x2x1"
.
SyN optimized for abpBrainExtraction, forces mutual information as optimization metric.
SyN, but optimized for registrations between BOLD and T1 images.
SyN, but optimized for registrations between BOLD and T1 images, with additional affine step.
SyN, but with more aggressive registration
(fine-scale matching and more deformation). Takes more time than SyN
.
time-varying diffeomorphism with where 'n' indicates number of time points in velocity field discretization. The initial transform should be computed, if needed, in a separate call to ants.registration.
time-varying diffeomorphism with mean square metric
time-varying diffeomorphism with mean square metric for very large deformation
simple elastic deformation. one might want to run an
affine transformation before this. may not produce diffeomorphic transformations.
user may need to explore gradient and sigma parameters. this will not produce a valid inverse deformation. totalSigma
should be greater than zero.
recreation of the antsRegistrationSyN.sh script in ANTs where 'x' is one of the transforms available (e.g., 't', 'b', 's')
recreation of the antsRegistrationSyNQuick.sh script in ANTs where 'x' is one of the transforms available (e.g., 't', 'b', 's')
reproducible registration. x options as above.
quick reproducible registration. x options as above.
outputs a list containing:
Moving image warped to space of fixed image.
Fixed image warped to space of moving image.
Transforms to move from moving to fixed image.
Transforms to move from fixed to moving image.
Ouptut of 1 indicates failure
Shrinidhi KL, Tustison NJ, Avants BB
# print help
antsRegistration()
fi <- antsImageRead(getANTsRData("r16"))
mi <- antsImageRead(getANTsRData("r64"))
mytx2 <- antsRegistration(fixed = fi, typeofTransform = "")
rig <- antsRegistration(
fixed = fi, moving = mi,
typeofTransform = "Rigid", verbose = TRUE
)
trans <- readAntsrTransform(rig$fwdtransforms, 2)
postrig <- antsRegistration(
fixed = fi, moving = mi,
typeofTransform = "Affine", initialTransform = trans
)
for (itype in c("AffineFast", "BOLDAffine")) {
print(itype)
mytx2 <- antsRegistration(
fixed = fi, moving = mi,
typeofTransform = itype
)
}
mytx2 <- antsRegistration(
fixed = fi, moving = mi,
typeofTransform = "SyNOnly",
multivariateExtras = list(list("MeanSquares", fi, mi, 0.5, 0))
)
testthat::expect_error(
antsRegistration(fixed = fi, moving = mi, typeofTransform = "sdf")
)
bad <- antsRegistration(fixed = fi, moving = mi, regIterations = 40)
affIterations <- c(3, 2, 1, 0)
mytx2 <- antsRegistration(
fixed = fi, moving = mi,
affIterations = affIterations
)
# set below for slower but numerically repeatable results
# these should be set in .Renviron not by sys calls
# Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1)
# Sys.setenv(ANTS_RANDOM_SEED = 20180716)
fi <- antsImageRead(getANTsRData("r16"))
mi <- antsImageRead(getANTsRData("r64"))
fi <- resampleImage(fi, c(60, 60), 1, 0)
mi <- resampleImage(mi, c(50, 50), 1, 0) # speed up
mytx <- antsRegistration(fixed = fi, moving = mi, typeofTransform = c("SyN"))
mywarpedimage <- antsApplyTransforms(
fixed = fi, moving = mi,
transformlist = mytx$fwdtransforms
)
mytx2 <- antsRegistration(fixed = fi, moving = mi, typeofTransform = c("SyN"))
mywarpedimage2 <- antsApplyTransforms(
fixed = fi, moving = mi,
transformlist = mytx2$fwdtransforms
)
# testthat::expect_equal(as.array(mywarpedimage), as.array(mywarpedimage2))
## Not run:
# quick visualization fix for images with odd orientation
mni <- antsImageRead(getANTsRData("mni"))
strokt1 <- antsImageRead("strokt1.nii.gz")
strokt1reg <- antsRegistration(
fixed = mni,
moving = strokt1,
typeofTransform = "QuickRigid", verbose = TRUE
)
plot(strokt1reg$warpedmovout, axis = 3, nslices = 20)
# now - how to use a mask
fi <- antsImageRead(getANTsRData("r16"))
fiseg <- kmeansSegmentation(fi, 3)
mi <- antsImageRead(getANTsRData("r64"))
msk <- thresholdImage(fiseg$segmentation, 0, 0)
mytx <- antsRegistration(
fixed = fi, moving = mi, typeofTransform = c("SyNCC"),
mask = msk, verbose = F
)
jac <- createJacobianDeterminantImage(fi, mytx$fwdtransforms[1])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.