View source: R/reliable_grayscale.R
| ensure_grayscale | R Documentation |
Improves on the XYZ method of grayscale by handling
alpha channel and retaining relative luminance of the image
ensure_grayscale(img, bg = 1)
img |
An |
bg |
Background color in case of alpha (default is white) |
An cimg object, now in grayscale (just one
color channel).
# Load image using imager
pineapple_img = load.image(system.file("FallingPineapple_16x16.png", package = "ort"))
# Create grayscale version
pineapple_gray = ensure_grayscale(pineapple_img)
plot(pineapple_gray)
# Example with alpha background
alph_img = load.image(system.file("alpha_gradient_test.png", package = "ort"))
# default assumes bg = 1 (white background)
alph_gray = ensure_grayscale(alph_img)
plot(alph_gray)
alph_gray_darker = ensure_grayscale(alph_img, bg = 0.75)
plot(alph_gray_darker)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.