img_indices: Retrieve Image Indices

View source: R/img_indices.R

img_indicesR Documentation

Retrieve Image Indices

Description

Extract image xyz indices (in voxels or millimeters), with the option to append the values

Usage

img_indices(img, mask = NULL, add_values = FALSE, units = c("index", "mm"))

Arguments

img

Object of class nifti

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.

Value

Matrix of 3 columns if add_values = FALSE or 4 columns, otherwise.

Examples

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"))

neurobase documentation built on May 29, 2024, 2:17 a.m.