Description Usage Arguments Details Value Examples
View source: R/01b_remove_background.R
Take an image array (from readPNG
or
jpeg{readJPEG}
) and remove the background pixels based on
transparency (if a PNG with transparency) or color boundaries.
1 2 3 4 5 6 7 | removeBackground(
img,
lower = NULL,
upper = NULL,
quietly = FALSE,
alpha.channel = TRUE
)
|
img |
Image array, either output from |
lower, upper |
RGB or HSV triplets specifying the bounds for background
pixels. See |
quietly |
Logical. Display a message if using transparency? |
alpha.channel |
Logical. If available, should alpha channel transparency be used to mask background? See details. |
If alpha.channel = TRUE
, transparency takes precedence over
color masking. If you provide a PNG with any pixels with alpha < 1,
removeBackground
ignores any lower
and upper
color
boundaries and assumes transparent pixels are background. If all pixels are
opaque (alpha = 1), color masking will apply.
A list with a 3-dimensional RGB array and a 2-dimensional array of non-background pixels with R, G, B columns.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # remove background by transparency
img_path <- system.file("extdata/chrysochroa_NPL.png",
package = "colordistance")
img_array <- png::readPNG(img_path)
img_filtered <- removeBackground(img_array)
# remove background by color
img_path <- dir(system.file("extdata/Heliconius",
package = "colordistance"),
recursive = TRUE, full.names = TRUE)[1]
img_array <- jpeg::readJPEG(img_path)
img_filtered <- removeBackground(img_array,
lower = rep(0.8, 3), upper = rep(1, 3))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.