Extract image xyz indices (in voxels or millimeters), with the option to append the values
img_indices(img, mask = NULL, add_values = FALSE, units = c("index", "mm"))
img | Object of class |
---|---|
mask | Mask to be applied for indices the index |
add_values | Should the value be column-bound to the matrix |
units | Should the indices be in xyz-coordinates or millimeters. |
Matrix of 3 columns if add_values = FALSE
or 4 columns,
otherwise.
set.seed(5)
dims = rep(10, 4)
arr = array(rpois(prod(dims), lambda = 2), dim = dims)
nim = oro.nifti::nifti(arr)
ind = img_indices(nim)
ind2 = img_indices(nim, mask = nim > 2)
# 3d example
set.seed(5)
dims = rep(10, 3)
arr = array(rpois(prod(dims), lambda = 2), dim = dims)
nim = oro.nifti::nifti(arr)
ind = img_indices(nim)
ind2 = img_indices(nim, mask = nim > 2)
testthat::expect_equal(colnames(ind2), c("x", "y", "z"))
ind2 = img_indices(nim, mask = nim > 2, add_values = TRUE)
testthat::expect_equal(colnames(ind2), c("x", "y", "z", "value"))