Learn R Programming

neurobase (version 1.32.4)

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

Value

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

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.

Examples

Run this code
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"))

Run the code above in your browser using DataLab