Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

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

'Neuroconductor' Base Package with Helper Functions for 'nifti' Objects

v1.32.1
GPL-2
Authors
John Muschelli [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.