R/dramms_defop_invert.R

Defines functions dramms_defop_invert

Documented in dramms_defop_invert

#' @title Run DRAMMS Deformation Inversion 
#'
#' @description Runs dramms_defop with inversion on deformation
#' @param def deformation field
#' @param retimg return nifti object versus output image
#' @param outfile Output filename 
#' 
#' @export
#' @return If \code{retimg = TRUE}, a \code{nifti} object.  
#' If \code{retimg = FALSE}, a the filename of the output image.
dramms_defop_invert <- function(
  def = NULL, # output deformation field
  outfile = NULL, # Output filename
  retimg = FALSE # return nifti object versus output image
){
  source = checkimg(def)
  outfile = check_outfile(outfile = outfile, retimg = retimg, fileext = ".nii.gz")
  
  args = c("--invert"=def, 
           outfile)
  cmd = "dramms-defop"
  cmd = dramms_cmd_maker(cmd=cmd, args = args)
  
  res = system(cmd)
  if (res != 0){
    stop("DRAMMS command failed")
  }
  
  if (retimg){
    img = readNIfTI(outfile, reorient=FALSE)
    return(img)
  }
  return(outfile)
}
muschellij2/drammsr documentation built on Jan. 18, 2021, 11:24 a.m.