This function calculates Local Moments (mean, standard deviation, skew) for an array.
local_moment( image, window = NULL, nvoxels = NULL, moment, mask = NULL, only.mask = FALSE, center = is.null(mean_image), invert = FALSE, mean_image = NULL, na.rm = TRUE, remask = TRUE, ... )
image | input image |
---|---|
window | window (in width) for the neighborhood |
nvoxels | window (in voxels) for the neighborhood 1 results in a 3x3 cube |
moment | vector moments taken (1- mean, 2-sd, 3-skew) |
mask | array or object of class nifti of same size as image |
only.mask | Should objects outside the mask (i.e. zeros) be counted the moment? Default is FALSE so edges are weighted to 0 |
center | vector of indicator of central moment. if TRUE mean image is subtracted. Same length as moment |
invert | Standardize the values by the power: 1/moment |
mean_image | mean image to be subtracted. If not supplied, and central = TRUE, local_moment_edge is run with mom = 1 |
na.rm | remove NAs from the moment image calculation |
remask | set areas outside of mask to 0 |
... | Arguments passed to |
List of arrays same lenght as moment
x = array(rnorm(1000), dim=c(10, 10, 10)) mask = abs(x) < 1 mean.x = local_moment(x, nvoxels=1, moment = 1, mask=mask, center = FALSE, remask = FALSE)[[1]] var.x = local_moment(x, nvoxels=1, moment = 2, mask=mask, center = TRUE, mean_image = mean.x, remask=FALSE)[[1]] ### check that x[2,2,2] mean is correct check = x[1:3,1:3,1:3] ## masking vals = check[abs(check) < 1] m = mean(vals) all.equal(m, mean.x[2,2,2])#> [1] "Mean relative difference: 0.4074074"#> [1] 0.2301687#> [1] "Mean relative difference: 0.4073575"