separate_img-methods: Separate Labeled Image into Multiple Binary Images

separate_img-methodsR Documentation

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 signature 'nifti'
separate_img(img, levels = NULL, drop_zero = TRUE)

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

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

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

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

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

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

Value

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

Note

Exact equalling is using ==

Examples

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)

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