Learn R Programming

neurobase (version 1.32.4)

separate_img-methods: Separate Labeled Image into Multiple Binary Images

Description

Takes in an image, gets the unique values, then creates a list of binary images for each one of those values.

Usage

separate_img(img, levels = NULL, drop_zero = TRUE)

# S4 method for nifti separate_img(img, levels = NULL, drop_zero = TRUE)

# S4 method for array separate_img(img, levels = NULL, drop_zero = TRUE)

# S4 method for ANY separate_img(img, levels = NULL, drop_zero = TRUE)

# S4 method for factor separate_img(img, levels = NULL, drop_zero = TRUE)

# S4 method for character separate_img(img, levels = NULL, drop_zero = TRUE)

# S4 method for list separate_img(img, levels = NULL, drop_zero = TRUE)

Value

A nifti object (or list of them) or class of object passed in if not specified

Arguments

img

character path of image or an object of class nifti, or list of images

levels

if levels is given, then the separation is only done for those levels and not unique values of the image.

drop_zero

Should zeroes be dropped from the labels? Zero usually denotes background or non-interesting voxels

Examples

Run this code
set.seed(5)
dims = rep(10, 3)
arr = array(rpois(prod(dims), lambda = 2), dim = dims)
nim = oro.nifti::nifti(arr)
simg = separate_img(nim)
simg_arr = separate_img(arr)
slist = lapply(simg, function(x) array(x, dim(x)))
testthat::expect_equal(slist, simg_arr)

rnifti = RNifti::asNifti(nim)
timg = tempimg(nim)
limg = list(factor(timg), factor(timg))
func = separate_img
func(arr)
func(nim)
func(rnifti)
func(timg)
func(limg)

Run the code above in your browser using DataLab