Created
December 22, 2012 20:34
-
-
Save josefslerka/4360941 to your computer and use it in GitHub Desktop.
Detekce dominatnich barev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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