Skip to contents

If a mask is specified, setTo sets the color of the parts of an image corresponding to the white parts of the mask to the desired color. If no mask is specified, the entire image is set to the desired color.

Usage

setTo(image, mask, color = "red", target = "new", in_place = NULL)

Arguments

image

An Image object.

mask

An 8U, single-channel Image object. The region to be colored should be non-zero.

color

A value or vector of any kind of R color specification compatible with col2bgr representing the color of each rectangle's outline (default: "red").

target

The location where the results should be stored. It can take 2 values:

  • "new":a new Image object is created and the results are stored inside (the default).

  • "self":the results are stored back into image (faster but destructive).

in_place

Deprecated. Use target instead.

Value

If target="new", the function returns an Image

object. If target="self", the function returns nothing and modifies

image in place.

See also

Author

Simon Garnier, garnier@njit.edu

Examples

balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
mask <- zeros(nrow(balloon), ncol(balloon), 1)
poly <- data.frame(x = c(290, 290, 440, 440), y = c(170, 325, 325, 170))
fillPoly(mask, poly, color = "white")
balloon_painted <- setTo(balloon, mask, "green")