Title: | Extract Colors from Windows BMP, JPEG, PNG, TIFF, and SVG Format Images |
---|---|
Description: | Extracts colors from various image types, returns customized reports and plots treemaps and 3D scatterplots of image compositions. Color palettes can also be created. |
Authors: | David Zumbach [aut, cre] |
Maintainer: | David Zumbach <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.4 |
Built: | 2025-02-11 02:57:07 UTC |
Source: | https://github.com/zumbov2/colorfindr |
get_colors
extract colors from Windows BMP, JPEG, PNG, TIFF, and SVG format images.
get_colors(img, exclude_col = NULL, exclude_rad = NULL, top_n = NULL, min_share = NULL, get_stats = TRUE)
get_colors(img, exclude_col = NULL, exclude_rad = NULL, top_n = NULL, min_share = NULL, get_stats = TRUE)
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 |
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.
# 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")
# 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")
make_palette
creates a color palette from colors extracted from Windows BMP, JPEG, PNG, TIFF, and SVG format images with
the get_colors
function.
make_palette(data, n = 10, clust_method = "kmeans", extract_method = "hex_freq", show = TRUE)
make_palette(data, n = 10, clust_method = "kmeans", extract_method = "hex_freq", show = TRUE)
data |
a |
n |
the number of discrete colors to be extracted from the data. |
clust_method |
specifies the method used to cluster the pixels. By default, the colors are clustered by the
|
extract_method |
specifies the process for extracting the colors from the clusters obtained. By default |
show |
by default |
A character vector with hex color codes, sorted by the weight of the associated clusters.
# Create palette from image img <- system.file("extdata", "pic6.png", package = "colorfindr") colors <- get_colors(img) make_palette(colors)
# Create palette from image img <- system.file("extdata", "pic6.png", package = "colorfindr") colors <- get_colors(img) make_palette(colors)
plot_colors
creates a treemap of colors extracted from Windows BMP, JPEG, PNG, TIFF, and SVG format images with
the get_colors
function.
plot_colors(data, sort = "color", labels = TRUE)
plot_colors(data, sort = "color", labels = TRUE)
data |
a |
sort |
specifies the sorting of the treemap rectangles. By default ( |
labels |
by default, rectangles that are sufficiently large are provided with a label. If |
# Extract all colors pic1 <- system.file("extdata", "pic1.png", package = "colorfindr") col <- get_colors(pic1) # Plot image composition plot_colors(col)
# Extract all colors pic1 <- system.file("extdata", "pic1.png", package = "colorfindr") col <- get_colors(pic1) # Plot image composition plot_colors(col)
plot_colors_3d
calls plotly
and creates an interactive 3D scatterplot of
colors extracted from Windows BMP, JPEG, PNG, TIFF, and SVG format images with the
get_colors
function in the RGB color space.
plot_colors_3d(data, sample_size = 5000, marker_size = 2.5, color_space = "RGB")
plot_colors_3d(data, sample_size = 5000, marker_size = 2.5, color_space = "RGB")
data |
a |
sample_size |
the number of pixels to randomly select. |
marker_size |
size of marker. |
color_space |
specifies color space. By default, the colors are displayed in the |
# Extract all colors pic1 <- system.file("extdata", "pic5.png", package = "colorfindr") col <- get_colors(pic1) # Plot image composition plot_colors_3d(col)
# Extract all colors pic1 <- system.file("extdata", "pic5.png", package = "colorfindr") col <- get_colors(pic1) # Plot image composition plot_colors_3d(col)