extract_colors | R Documentation |
The function extracts the most prominent Colors of a given Picture (jpeg or png format) by kmeans clustering algorithm. The picture must be loaded with readPNG() or readJPEG() from the packages 'png' or 'jpeg'. With n the user can set the number of clusters (colors to be extracted). The standard value is 6.
extract_colors(image, n = 6, plot_out = F)
image |
matrix; must contain color information for each pixel of the picture. (use readPNG or readJPEG functions to obtain the right data structure) |
n |
numeric; Number of colors to be extracted from the picture |
plot_out |
logical; If TRUE a plot of the picture containing only the extracted colors will be generated |
data.frame; containing the extracted colors (r,g and b value and the corresponding hex code)
# extract the 4 most prominent colors from the example picture primroses
# extract_colors(primroses, n = 4)
# show the picture with the reduced number of colors
# extract_colors(primroses, n = 4, plot_out = T)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.