R/compose_transform_to_file.R

Defines functions compose_transform_to_file

Documented in compose_transform_to_file

#' Compose Transforms from ANTsR to a composite file
#' 
#' This is a thin wrapper for \code{\link{antsApplyTransforms}} but 
#' is specifically for composing a transform and getting a file out.
#'
#' @param fixed fixed image defining domain into which the moving image is transformed.
#' @param moving moving image to be mapped to fixed space.
#' @param transformlist haracter vector of transforms generated by 
#' \code{\link{antsRegistration}} where each transform is a filename.
#' @param output_prefix Prefix of output filename to return.  The prefix will
#' add \code{comptx.nii.gz} to the end
#'
#' @return A character filename
#' @export
#'
#' @examples
#' library(ANTsR)
#' fixed <- antsImageRead( getANTsRData("r16") ,2)
#' moving <- antsImageRead( getANTsRData("r64") ,2)
#' fixed <- resampleImage(fixed,c(64,64),1,0)
#' moving <- resampleImage(moving,c(64,64),1,0)
#' mytx <- antsRegistration(fixed=fixed , moving=moving ,
#'                          typeofTransform = c("SyN"), 
#'                          verbose = TRUE
#'                           )
#' composed <- compose_transform_to_file( 
#' fixed=fixed, moving=moving, transformlist=mytx$fwdtransforms)
compose_transform_to_file = function(
  fixed, moving, 
  transformlist = NULL,
  output_prefix = NULL) {
  fixed = check_ants(fixed)
  moving = check_ants(moving)
  if (is.null(transformlist)) {
    stop("transformlist needs to be set")
  }
  if (!is.character(transformlist)) {
    stop("transformlist needs to be a character vector")
  }
  if (is.null(output_prefix)) {
    output_prefix = tempfile()
  }
  
  fixed = antsImageClone(fixed)
  moving = antsImageClone(moving)
  
  result = antsApplyTransforms(
    fixed = fixed,
    moving = moving,
    transformlist = transformlist,
    compose = output_prefix
  )
  return(result)
}
neuroconductor-releases/extrantsr documentation built on Dec. 10, 2019, 12:07 a.m.