Register a pair of images either through the full or simplified interface to the ANTs registration method.

antsRegistration(fixed = NA, moving = NA, typeofTransform = "SyN",
  initialTransform = NA, outprefix = NULL, mask = NA,
  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, verbose = FALSE,
  printArgs = FALSE, ...)

Arguments

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 Details.

initialTransform

transforms to prepend

outprefix

output will be named with this prefix.

mask

mask the registration. can be a single mask or pair of the form list(maskFixed,maskMoving)

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 nbins or radius parameter for the syn 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 list( list( "nameOfMetric2", img, img, weight, metricParam ) ) . Another example would be list( list( "MeanSquares", f2, m2, 0.5, 0 ), list( "CC", f2, m2, 0.5, 2 ) ) . This is only compatible with the SyNOnly transformation.

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 c(1,1,0) for a 3D deformation field or c(1,1,0,1,1,0) for a rigid transformation. Restriction currently only works if there are no preceding transformations.

writeCompositeTransform

if TRUE, will write transformations to h5 format. Defaults to FALSE.

verbose

request verbose output (useful for debugging)

printArgs

print raw command line (useful for debugging)

...

additional options see antsRegistration in ANTs

Value

outputs a list containing:

  • warpedmovout: Moving image warped to space of fixed image.

  • warpedfixout: Fixed image warped to space of moving image.

  • fwdtransforms: Transforms to move from moving to fixed image.

  • invtransforms: Transforms to move from fixed to moving image.

Ouptut of 1 indicates failure

Details

typeofTransform can be one of:

  • "Translation": Translation transformation.

  • "Rigid": Rigid transformation: Only rotation and translation.

  • "Similarity": Similarity transformation: scaling, rotation and translation.

  • "QuickRigid": Rigid transformation: Only rotation and translation. May be useful for quick visualization fixes.'

  • "DenseRigid": Rigid transformation: Only rotation and translation. Employs dense sampling during metric estimation.'

  • "BOLDRigid": Rigid transformation: Parameters typical for BOLD to BOLD intrasubject registration'.'

  • "Affine": Affine transformation: Rigid + scaling.

  • "AffineFast": Fast version of Affine.

  • "BOLDAffine": Affine transformation: Parameters typical for BOLD to BOLD intrasubject registration'.'

  • "TRSAA": 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).

  • "ElasticSyN": Symmetric normalization: Affine + deformable transformation. Uses synMetric as optimization metric and elastic regularization.

  • "SyN": Symmetric normalization: Affine + deformable transformation. Uses synMetric as optimization metric.

  • "SyNRA": Symmetric normalization: Rigid + Affine + deformable transformation. Uses synMetric as optimization metric.

  • "SyNOnly": 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.

  • "SyNCC": 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".

  • "SyNabp": SyN optimized for abpBrainExtraction, forces mutual information as optimization metric.

  • "SyNBold": SyN, but optimized for registrations between BOLD and T1 images.

  • "SyNBoldAff": SyN, but optimized for registrations between BOLD and T1 images, with additional affine step.

  • "SyNAggro": SyN, but with more aggressive registration (fine-scale matching and more deformation). Takes more time than SyN.

  • "TVMSQ": time-varying diffeomorphism with mean square metric

  • "TVMSQC": time-varying diffeomorphism with mean square metric for very large deformation

  • "Elastic": 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.

Examples

#print help antsRegistration()
#> for simplified mode: #> antsRegistration( fixed , moving , typeofTransform = c("Rigid","Affine","AffineFast","SyN","SyNCC"), outputPrefix="./antsRegOut" #> For full mode: use standard ants call , e.g. : #> ANTsR::antsRegistration( list( d=2,m="mi[r16slice.nii.gz,r64slice.nii.gz,1,20,Regular,0.05]", t="affine[1.0]", c="2100x1200x1200x0", s="3x2x1x0", f="4x3x2x1", u="1", o="[xtest,xtest.nii.gz,xtest_inv.nii.gz]" ) ) #> full help:
#> [1] 0
fi <- antsImageRead(getANTsRData("r16") ) mi <- antsImageRead(getANTsRData("r64") ) mytx2 <- antsRegistration(fixed=fi, typeofTransform = '')
#> for simplified mode: #> antsRegistration( fixed , moving , typeofTransform = c("Rigid","Affine","AffineFast","SyN","SyNCC"), outputPrefix="./antsRegOut" #> For full mode: use standard ants call , e.g. : #> ANTsR::antsRegistration( list( d=2,m="mi[r16slice.nii.gz,r64slice.nii.gz,1,20,Regular,0.05]", t="affine[1.0]", c="2100x1200x1200x0", s="3x2x1x0", f="4x3x2x1", u="1", o="[xtest,xtest.nii.gz,xtest_inv.nii.gz]" ) ) #> full help:
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) }
#> [1] "AffineFast" #> [1] "BOLDAffine"
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] ) # }