Overloaded Mean for antsImage objects

# S3 method for class 'antsImage'
mean(x, ..., mask = NULL, na.rm = FALSE)

Arguments

x

is an object of class antsImage.

...

additional arguments to pass to mean

mask

binary mask of values to subset

na.rm

Remove missing values

Details

#' @rdname antsImagemath #' @aliases xor,antsImage-method setMethod(f = "xor", signature(x = "antsImage", y = "antsImage"), definition = function(x) xx = as.array(x) yy = as.array(y) xor(xx, yy) !a2 )

Examples

img <- makeImage(c(10, 10, 10), rnorm(1000))
mean(img)
#> [1] -0.001482656
mean(img, na.rm = TRUE)
#> [1] -0.001482656
mean(img > 0)
#> [1] 0.491
mean(img > 0, na.rm = TRUE)
#> [1] 0.491
mean(img, mask = img > 0)
#> [1] 0.8404062
mean(img, mask = img > 0, na.rm = TRUE)
#> [1] 0.8404062
arr <- as.array(img)
arr[1, 1, 1] <- NA
img <- as.antsImage(arr, reference = img)
m <- mean(img)
stopifnot(is.nan(m))
mean(img, na.rm = TRUE)
#> [1] -0.0009098952
m <- mean(0 < img)
stopifnot(is.nan(m))
m <- mean(img > 0)
# stopifnot(is.nan(m))
mean(img > 0, na.rm = TRUE)
#> [1] 0.492
m <- mean(img, mask = img > 0)
stopifnot(is.nan(m))
mean(img, mask = img > 0, na.rm = TRUE)
#> [1] 0.8404062