Learn R Programming

fslr (version 1.9.2.1)

zscore_img: Get Z-score over a margin of an img

Description

Standardizes an image either by the axial, sagittal, or coronal slice

Usage

zscore_img(img, mask = NULL, margin = 3, centrality = c("mean", "median"), variability = c("sd", "iqrdiff", "mad", "maddiff", "iqr"), remove.na = TRUE, remove.nan = TRUE, remove.inf = TRUE, remove.val = 0)

Arguments

img
character path of image or an object of class nifti
mask
character path of mask or an object of class nifti
margin
Margin of image to z-score over (3-Axial, 2-Sagittal, 1-Coronal)
centrality
(character) Measure to center the data, either mean or median
variability
(character) Measure to scale the data
remove.na
(logical) change NAs to remove.val
remove.nan
(logical) change NaN to remove.val
remove.inf
(logical) change Inf to remove.val
remove.val
(logical) value to put the NA/NaN/Inf

Value

Array of object of class nifti

See Also

aperm

Examples

Run this code
dim = c(100, 30, 5)
img = array(rnorm(prod(dim), mean=4, sd=4), 
dim=dim)

truth2 = img
for (i in 1:dim(img)[2]) {
truth2[,i,] = (truth2[,i,]- mean(truth2[,i,]))/sd(truth2[,i,])
}

truth1 = img
for (i in 1:dim(img)[1]) {
truth1[i,,] = (truth1[i,,]- mean(truth1[i,,]))/sd(truth1[i,,])
}

truth3 = img
for (i in 1:dim(img)[3]) {
truth3[,,i] = (truth3[,,i]- mean(truth3[,,i]))/sd(truth3[,,i])
}
try3 = zscore_img(img, margin=3)
stopifnot(all.equal(try3, truth3))
try2 = zscore_img(img, margin=2)
stopifnot(all.equal(try2, truth2))
try1 = zscore_img(img, margin=1)
stopifnot(all.equal(try1, truth1))
  

Run the code above in your browser using DataLab