Make im3d image array containing values at locations defined by a mask

unmask(
  x,
  mask,
  default = NA,
  attributes. = attributes(mask),
  copyAttributes = TRUE
)

Arguments

x

the data to place on a regular grid

mask

An im3d regular image array where non-zero voxels are the selected element.

default

Value for regions outside the mask (default: NA)

attributes.

Attributes to set on new object. Defaults to attributes of mask

copyAttributes

Whether to copy over attributes (including dim) from the mask to the returned object. default: TRUE

Value

A new im3d object with attributes/dimensions defined by mask and values from x. If copyAttributes is FALSE, then it will have mode of x and length of mask but no other attributes.

Details

The values in x will be placed into a grid defined by the dimensions of the mask in the order defined by the standard R linear subscripting of arrays (see e.g. arrayInd).

See also

Examples

if (FALSE) {
# read in a mask
LHMask=read.im3d(system.file('tests/testthat/testdata/nrrd/LHMask.nrrd', package='nat'))
# pick out all the non zero values
inmask=LHMask[LHMask!=0]
# fill the non-zero elements of the mask with a vector that iterates over the
# values 0:9
stripes=unmask(seq(inmask)%%10, LHMask)
# make an image from one slice of that result array
image(imslice(stripes,11), asp=TRUE)
}