paint_with_mask: Paint with mask

View source: R/paint_with_mask.R

paint_with_maskR Documentation

Paint with mask

Description

Paint image pixels inside or outside a logical mask with a solid color.

Usage

paint_with_mask(r, m, color = "red", where = "outside")

Arguments

r

terra::SpatRaster. The image. Values should be normalized, see normalize_minmax(). Only images with one or three layers are supported.

m

logical terra::SpatRaster with one layer. A binary mask with TRUE for selected pixels.

color

character vector of length one or numeric vector of length three. Fill color. If character, it is converted to RGB automatically. If numeric, values must be in range [0, 1].

where

character vector of length one Region to paint relative to m. Either "outside" (default) or "inside".

Value

numeric terra::SpatRaster with three layers and the geometry of r. Equal to r, but with pixels in the selected region painted with color. Single-layer inputs are replicated to allow color painting.

Examples

## Not run: 
r <- read_caim()
z <- zenith_image(ncol(r), lens())
a <- azimuth_image(z)
m <- select_sky_region(z, 20, 70) & select_sky_region(a, 90, 180)

masked_caim <-  paint_with_mask(normalize_minmax(r), m)
plotRGB(masked_caim * 255)

masked_bin <- paint_with_mask(binarize_with_thr(r$Blue, 125), m)
plotRGB(masked_bin * 255)

r <- normalize_minmax(r)
paint_with_mask(r, m, color = c(0.2, 0.2, 0.2))  # vector
paint_with_mask(r, m, color = "blue")     # name
paint_with_mask(r, m, color = "#00FF00")  # hexadecimal

## End(Not run)

rcaiman documentation built on Sept. 9, 2025, 5:42 p.m.