count_colors: Count colors based on proximity to centers

Description Usage Arguments Value Examples

View source: R/colors.R

Description

Colors in colors are binned to the closest colors in centers based on Euclidean distance in the color space provided in colorspace. These are then tabulated to give the number of pixels of each color in centers.

Usage

1
count_colors(colors, centers, colorspace)

Arguments

colors

colors to be tabulated as a colorspace::color object, e.g. colorspace::RGB.

centers

colors to be used for binning as a colorspace::color object, e.g. colorspace::RGB.

colorspace

string describing the colorspace in which distances should be calculated, e.g. "RGB", "LAB", "LUV".

Value

tibble with as many rows as centers with the columns freq and hex, as well as columns corresponding to the dimensions of colorspace

Examples

1
2
3
4
5
example_jpg <- system.file("extdata", "example.JPG", package = "routes")
read_pixels(example_jpg) %>% 
  colorspace::RGB() %>%
  count_colors(centers = colorspace::RGB(c(1, 0, 0), c(0, 1, 0),  c(0, 0, 1)),
    colorspace = "RGB") 

cwickham/routes documentation built on Nov. 4, 2019, 9:34 a.m.