Description Usage Arguments Value Examples
View source: R/02c_kmeans_color_clustering.R
Uses KMeans clustering to determine color clusters that minimize the sum of distances between pixels and their assigned clusters. Useful for parsing common color motifs in an object.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | getKMeanColors(
  path,
  n = 10,
  sample.size = 20000,
  plotting = TRUE,
  lower = c(0, 0.55, 0),
  upper = c(0.24, 1, 0.24),
  iter.max = 50,
  nstart = 5,
  return.clust = TRUE,
  color.space = "rgb",
  from = "sRGB",
  ref.white
)
 | 
| path | Path to an image (JPG or PNG). | 
| n | Number of KMeans clusters to fit. Unlike  | 
| sample.size | Number of pixels to be randomly sampled from filtered pixel
array for performing fit. If set to  | 
| plotting | Logical. Should the results of the KMeans fit (original image + histogram of colors and bin sizes) be plotted? | 
| lower | RGB triplet specifying the lower bounds for background pixels. Default upper and lower bounds are set to values that work well for a bright green background (RGB [0, 1, 0]). | 
| upper | RGB triplet specifying the upper bounds for background pixels. Default upper and lower bounds are set to values that work well for a bright green background (RGB [0, 1, 0]). Determining these bounds may take some trial and error, but the following bounds may work for certain common background colors: 
  If no background filtering is
needed, set bounds to some non-numeric value ( | 
| iter.max | Inherited from  | 
| nstart | Inherited from  | 
| return.clust | Logical. Should clusters be returned? If  | 
| color.space | The color space ( | 
| from | Display color space of image if clustering in CIE Lab space, probably either "sRGB" or "Apple RGB", depending on your computer. | 
| ref.white | The reference white passed to
 | 
A kmeans fit object.
| 1 2 3 | colordistance::getKMeanColors(system.file("extdata",
"Heliconius/Heliconius_B/Heliconius_07.jpeg", package="colordistance"), n=3,
return.clust=FALSE, lower=rep(0.8, 3), upper=rep(1, 3))
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.