get_colors {colorfindr} | R Documentation |
Extract colors from images.
Description
get_colors
extract colors from Windows BMP, JPEG, PNG, TIFF, and SVG format images.
Usage
get_colors(img, exclude_col = NULL, exclude_rad = NULL, top_n = NULL,
min_share = NULL, get_stats = TRUE)
Arguments
img |
path or url to image. |
exclude_col |
vector of colors to be excluded from the analysis. The built-in colors (see |
exclude_rad |
numeric vector with blurring of the colors to be excluded. Corresponds to a maximum spherical distance
in the RGB color space (all dimensions range from 0 to 255). If |
top_n |
display the most frequent colors. |
min_share |
display the colors with a minimum share of all pixels (0-1). |
get_stats |
if |
Value
If get_stats
is set to FALSE
a character vector
containing the hex color codes is returned. Otherwise,
a data.frame
(tibble::tibble
) is returned with the following columns:
-
col_hex
hex color code. -
col_freq
absolute frequency of the color. -
col_share
relative frequency of the color.
Examples
# Extract all colors
pic1 <- system.file("extdata", "pic1.png", package = "colorfindr")
get_colors(pic1)
# Extract three most frequent colors
pic2 <- system.file("extdata", "pic2.tif", package = "colorfindr")
get_colors(pic2, top_n = 3)
# Extract colors that fill over 20% of the area
pic3 <- system.file("extdata", "pic3.jpg", package = "colorfindr")
get_colors(pic3, min_share = 0.2)
# Extract all colors except white
pic4 <- system.file("extdata", "pic4.bmp", package = "colorfindr")
get_colors(pic4, exclude_col = "white")