Skip to content

Instantly share code, notes, and snippets.

@josefslerka
Created December 22, 2012 20:34
Show Gist options
  • Save josefslerka/4360941 to your computer and use it in GitHub Desktop.
Save josefslerka/4360941 to your computer and use it in GitHub Desktop.
Detekce dominatnich barev
#short version of this GIST https://gist.github.com/3980277
library("ReadImages")
library("reshape")
library("ggplot2")
#detekce dominatnich barev
readImage <- read.jpeg("File5196.jpg")
longImage <- melt(readImage)
rgbImage <- reshape(longImage, timevar = "X3", idvar = c("X1", "X2"), direction = "wide")
rgbImage$X1 <- -rgbImage$X1
kColors <- 5 # Number of palette colors
kMeans <- kmeans(rgbImage[, 3:5], centers = kColors)
approximateColor <- kMeans$centers[kMeans$cluster, ]
col = rgb(approximateColor)
barvy <- sort(table(col))
barva <- row.names(barvy)
barplot(barvy, col=barva, horiz=TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment