Image Color Recognition, The General Color
I want to get the most prominent color of an image, and the language can be in either python or ruby. Is this easily done?
Solution 1:
I don't know if this is what you mean, but maybe it will be helpful:
require'rubygems'require'RMagick'
include Magick
image = Image.read("stack.png")[0]
hash = image.color_histogram
color, number = hash.max{|a,b| a[1] <=> b[1]}
puts color.to_color
This worked like a charm for very simple image (only 5 colors), but should work for more complex images too (I did not tested that; returned hash will be quite big in that case, so you might want to use quantize on your image before using color_histogram).
Some resources :
I hope this was useful to you. :)
Solution 2:
OK. Let me introduce the library for Ruby.
Using Camellia, http://camellia.sourceforge.net/examples.html, you can label the area with the most prominent color.
Solution 3:
Not sure if this is what you mean, but the Python PIL has im.histogram() and im.getcolors() functions. http://effbot.org/imagingbook/image.htm
Post a Comment for "Image Color Recognition, The General Color"