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 colors()) and/or hex color codes can be used.

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 is.null, only the exact colors are excluded. If input is of length 1, the same blurring is applied to all elements of exclude_col.

top_n

display the most frequent colors.

min_share

display the colors with a minimum share of all pixels (0-1).

get_stats

if TRUE, absolute and relative frequency of the colors are also included in the response.

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:

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")


[Package colorfindr version 0.1.4 Index]