Learn R Programming

Rvision (version 0.4.2)

setTo: Set All or Some of an Image to the Specified Value

Description

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", in_place = FALSE)

Arguments

image

An Image object.

mask

An 8-bit Image object. The region to be colored should be white.

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").

in_place

A logical indicating whether the change should be applied to the image itself (TRUE, faster but destructive) or to a copy of it (FALSE, the default, slower but non destructive).

Value

An Image object if in_place=FALSE. Otherwise, it returns nothing and modifies image in place.

See Also

Image

Examples

Run this code
# NOT RUN {
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
mask <- zeros(nrow(balloon), ncol(balloon))
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")
plot(balloon_painted)

# }

Run the code above in your browser using DataLab