img_indices: Retrieve Image Indices

Description Usage Arguments Value Examples

View source: R/img_indices.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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"))

neuroconductor/neurobase documentation built on May 19, 2021, 5:24 a.m.