maskImage: Mask input image by mask image.

Description Usage Arguments Value Author(s) Examples

View source: R/maskImage.R

Description

Mask an input image by a mask image. If the mask image has multiple labels, it is possible to specify which label(s) to mask at.

Usage

1
maskImage(img.in, img.mask, level = 1, binarize = FALSE)

Arguments

img.in

Input image.

img.mask

Mask or label image.

level

Level(s) at which to mask image. If vector or list of values, output image is non-zero at all locations where label image matches any of the levels specified.

binarize

binarize the output image?

Value

An object of type antsImage.

Author(s)

Kandel BM and Avants B.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
myimg <- antsImageRead(getANTsRData("r16"))
mask <- getMask(myimg)
myimg.mask <- maskImage(myimg, mask, 3)
testthat::expect_equal(sum(myimg.mask), 0)
myimg.mask <- maskImage(myimg, mask)
testthat::expect_equal(sum(myimg.mask), 3295494)
# set below for slower but numerically repeatable results
# these should be set in .Renviron not by sys calls
# Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1)
seg <- kmeansSegmentation(myimg, 3)
myimg.mask <- maskImage(myimg, seg$segmentation, c(1,3))
check = myimg * (seg$segmentation == 1 | seg$segmentation == 3)
testthat::expect_equal(myimg.mask, check)
myimg.mask <- maskImage(myimg, seg$segmentation, c(1,3), binarize = TRUE)
coerce_mask(myimg.mask, error = TRUE) # no error

muschellij2/atropos documentation built on Oct. 11, 2018, 12:24 a.m.