extract_colors: Extract Color From Picture

View source: R/colors.R

extract_colorsR Documentation

Extract Color From Picture

Description

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.

Usage

extract_colors(image, n = 6, plot_out = F)

Arguments

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

Value

data.frame; containing the extracted colors (r,g and b value and the corresponding hex code)

Examples

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

PhilippJanitza/rootdetectR documentation built on Feb. 24, 2024, 6:46 a.m.