image_alpha {pliman} | R Documentation |
Add Alpha Layer to an RGB Image
Description
This function adds an alpha (transparency) layer to an RGB image using the EBImage package. The alpha layer can be specified as a single numeric value for uniform transparency or as a matrix/array matching the dimensions of the image for varying transparency.
Usage
image_alpha(img, mask)
Arguments
img |
An RGB image of class |
mask |
A numeric value or matrix/array specifying the alpha layer:
* If |
Value
An Image
object with an added alpha layer, maintaining the RGBA format.
Examples
if (interactive() && requireNamespace("EBImage")) {
# Load the EBImage package
library(pliman)
# Load a sample RGB image
img <- image_pliman("soybean_touch.jpg")
# 50% transparency
image_alpha(img, 0.5) |> plot()
# transparent background
mask <- image_binary(img, "NB")[[1]]
img_tb <- image_alpha(img, mask)
plot(img_tb)
}
[Package pliman version 3.0.0 Index]