Type: | Package |
Title: | Extract Colors from Windows BMP, JPEG, PNG, TIFF, and SVG Format Images |
Version: | 0.1.5 |
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. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Encoding: | UTF-8 |
BugReports: | https://github.com/zumbov2/colorfindr/issues |
RoxygenNote: | 7.3.2 |
Imports: | purrr, stringr, pixmap, tibble, treemap, rsvg, png, jpeg, tiff, bmp, dplyr, plotly, magrittr, plotwidgets |
NeedsCompilation: | no |
Packaged: | 2025-04-29 07:37:44 UTC; DavidZumbach |
Author: | David Zumbach [aut, cre] |
Maintainer: | David Zumbach <david.zumbach@gfzb.ch> |
Repository: | CRAN |
Date/Publication: | 2025-04-29 07:50:03 UTC |
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")
Create a color palette from an image.
Description
make_palette
creates a color palette from colors extracted from Windows BMP, JPEG, PNG, TIFF, and SVG format images with
the get_colors
function.
Usage
make_palette(
data,
n = 10,
clust_method = "kmeans",
extract_method = "hex_freq",
show = TRUE
)
Arguments
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 |
Value
A character vector with hex color codes, sorted by the weight of the associated clusters.
Examples
# Create palette from image
img <- system.file("extdata", "pic6.png", package = "colorfindr")
colors <- get_colors(img)
make_palette(colors)
Create treemaps of image color compositions
Description
plot_colors
creates a treemap of colors extracted from Windows BMP, JPEG, PNG, TIFF, and SVG format images with
the get_colors
function.
Usage
plot_colors(data, sort = "color", labels = TRUE)
Arguments
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 |
Examples
# Extract all colors
pic1 <- system.file("extdata", "pic1.png", package = "colorfindr")
col <- get_colors(pic1)
# Plot image composition
plot_colors(col)
Create interactive 3D scatterplots of image color compositions
Description
plot_colors_3d
calls plot_ly
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.
Usage
plot_colors_3d(
data,
sample_size = 5000,
marker_size = 2.5,
color_space = "RGB"
)
Arguments
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 |
Examples
# Extract all colors
pic1 <- system.file("extdata", "pic5.png", package = "colorfindr")
col <- get_colors(pic1)
# Plot image composition
plot_colors_3d(col)