Skip to content

Commit

Permalink
Merge branch 'master' into TransformMultiChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
stnava committed Apr 26, 2019
2 parents dcc63c4 + a9904eb commit 0b66c01
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 26 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -102,6 +102,7 @@ export(cropIndices)
export(decropImage)
export(denoiseImage)
export(direction)
export(displacementFieldFromAntsrTransform)
export(error_not_antsImage)
export(extractSlice)
export(getANTsRData)
Expand Down
30 changes: 18 additions & 12 deletions R/antsAverageImages.R
@@ -1,9 +1,10 @@
#' @title Computes average of image list
#' @title Computes average of image list
#'
#' @description Calculate the mean of a list of antsImages
#' @description Calculate the mean of a list of antsImages
#' @param imageList list of antsImages or a character vector of filenames
#' @param normalize boolean determines if image is divided by mean before
#' averaging
#' @param weights a vector of weights of length equal to imageList
#' @author Avants BB, Pustina D
#' @examples
#' f1 = getANTsRData('r16')
Expand All @@ -19,11 +20,11 @@
#' testthat::expect_error(antsAverageImages(list(r64, bad)))
#' diff_size = as.antsImage(r64[1:10, 1:10], ref = r64)
#' testthat::expect_error(antsAverageImages(list(r64, diff_size)))
#'
#'
#' @export
antsAverageImages <- function( imageList, normalize = FALSE)
antsAverageImages <- function( imageList, normalize = FALSE, weights )
{

# determine if input is list of images or filenames
isfile = FALSE
if (class(imageList) == 'character') {
Expand All @@ -32,18 +33,23 @@ antsAverageImages <- function( imageList, normalize = FALSE)
}
isfile = TRUE
}

# create empty average image
if (isfile) {
avg = antsImageRead(imageList[1])*0
masterdim = dim(avg)
} else {
} else {
avg <- imageList[[1]] * 0
}

# average them
if ( missing( "weights") )
weights = rep( 1.0 / length( imageList ), length( imageList ) )
if ( length( weights ) != length( imageList ) )
stop( "length( weights ) != length( imageList )" )
ct = 1
for ( i in imageList ) {

if (isfile) {
img = antsImageRead(i)
if ( any(dim(img) != masterdim) ) {
Expand All @@ -53,12 +59,12 @@ antsAverageImages <- function( imageList, normalize = FALSE)
} else {
img = i
}

if ( normalize ) {
img <- img / mean( img )
}
avg <- avg + img
avg <- avg + img * weights[ ct ]
ct = ct + 1
}
avg <- avg / length(imageList)
return( avg )
}
22 changes: 21 additions & 1 deletion R/antsRegistration.R
Expand Up @@ -87,6 +87,8 @@
#' \item{"TVMSQ": }{time-varying diffeomorphism with mean square metric}
#' \item{"TVMSQC": }{time-varying diffeomorphism with mean square metric
#' for very large deformation}
#' \item{"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. \code{totalSigma} should be greater than zero.}
#' }
#' @return outputs a list containing:
#' \itemize{
Expand Down Expand Up @@ -296,7 +298,7 @@ antsRegistration <- function(
# change this to a match.arg
allowableTx <- c("Translation","Rigid", "Similarity", "Affine", "TRSAA",
"SyN","SyNRA","SyNOnly","SyNCC","SyNabp", "SyNBold", "SyNBoldAff",
"SyNAggro", "SyNLessAggro", "TVMSQ","TVMSQC","ElasticSyN")
"SyNAggro", "SyNLessAggro", "TVMSQ","TVMSQC","ElasticSyN","Elastic")
ttexists <- typeofTransform %in% allowableTx
if (ttexists) {
initx = initialTransform
Expand Down Expand Up @@ -614,6 +616,24 @@ antsRegistration <- function(
if ( !is.na(maskopt) )
args=lappend( args, list( "-x", maskopt ) ) else args=lappend( args, list( "-x", "[NA,NA]" ) )
}

if ( typeofTransform == "Elastic" ) {
if ( is.na(gradStep) ) gradStep=0.25
tvtx=paste("GaussianDisplacementField[",
gradStep,",",flowSigma,",",totalSigma,"]",sep='')
args <- list("-d", as.character(fixed@dimension), "-r", initx,
"-m", paste(synMetric,"[", f, ",", m, ",1,",synSampling,"]", sep = ""),
"-t", tvtx,
"-c", paste("[",synits,",1e-7,8]",collapse=''),
"-s", smoothingsigmas,
"-f", shrinkfactors,
"-u", "0", "-z", "1", "-l", myl,
"-o", paste("[", outprefix, ",", wmo, ",", wfo, "]", sep = ""))
if ( !is.na(maskopt) )
args=lappend( args, list( "-x", maskopt ) ) else args=lappend( args, list( "-x", "[NA,NA]" ) )
}


if ( typeofTransform == "Rigid" |
typeofTransform == "Similarity" |
typeofTransform == "Translation" |
Expand Down
20 changes: 15 additions & 5 deletions R/antsrTransform_class.R
Expand Up @@ -201,7 +201,7 @@ getAntsrTransformParameters <- function(transform) {
return(.Call("antsrTransform_GetParameters", transform, PACKAGE = "ANTsRCore"))
}

#' @title setAntsrTransformParameters
#' @title setAntsrTransformFixedParameters
#' @description Set parameters of transform
#' @param transform antsrTransform
#' @param parameters array of parameters'
Expand All @@ -215,10 +215,10 @@ setAntsrTransformFixedParameters <- function(transform, parameters) {
invisible(.Call("antsrTransform_SetFixedParameters", transform, parameters, PACKAGE = "ANTsRCore"))
}

#' @title getAntsrTransformParameters
#' @description Get parameters of transform
#' @title getAntsrTransformFixedParameters
#' @description Get fixed parameters of transform
#' @param transform antsrTransform
#' @return array of parameters'
#' @return array of fixed parameters
#' @examples
#' tx = new("antsrTransform")
#' params = getAntsrTransformFixedParameters(tx)
Expand All @@ -227,7 +227,7 @@ getAntsrTransformFixedParameters <- function(transform) {
return(.Call("antsrTransform_GetFixedParameters", transform, PACKAGE = "ANTsRCore"))
}

#' @title getAntsrTransformParameters
#' @title antsrTransformFromDisplacementField
#' @description Convert deformation field (multiChannel image) to antsrTransform
#' @param field deformation field (multiChannel image)
#' @return antsrTransform'
Expand All @@ -236,6 +236,16 @@ antsrTransformFromDisplacementField <- function( field ) {
return(.Call("antsrTransform_FromDisplacementField", field, PACKAGE="ANTsRCore"))
}

#' @title displacementFieldFromAntsrTransform
#' @description Conver antsrTransform to displacement field
#' @param tx antsrTransform
#' @param reference reference antsImage if converting linear transform
#' @return antsImage
#' @export
displacementFieldFromAntsrTransform <- function( tx, reference=NA ) {
return(.Call("antsrTransform_ToDisplacementField", tx, ref, PACKAGE="ANTsRCore"))
}

#' @title applyAntsrTransform
#' @description Apply transform to point, vector or antsImage data
#' @param transform antsrTransform
Expand Down
4 changes: 2 additions & 2 deletions data/antsVersions.csv
@@ -1,3 +1,3 @@
Dependency;GitTag
ANTs;23e88fe16fde013909f601438f5407079eb0ad57
ANTsRCore;811354209d079d146cbb30c55821817f5d421cf5
ANTs;680942c1628c8ed142c6b25a4c8b9e47aadf3e01
ANTsRCore;a1b732bae6716713407a14b3fcce3b5d81b12fe7
4 changes: 3 additions & 1 deletion man/antsAverageImages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/antsRegistration.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/antsrTransformFromDisplacementField.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/displacementFieldFromAntsrTransform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/getAntsrTransformFixedParameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/setAntsrTransformFixedParameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b66c01

Please sign in to comment.