image_alpha | R Documentation |
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.
image_alpha(img, mask)
img |
An RGB image of class |
mask |
A numeric value or matrix/array specifying the alpha layer:
* If |
An Image
object with an added alpha layer, maintaining the RGBA format.
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.