图像颜色识别,一般颜色
我想获得图像最突出的颜色,语言可以是python或ruby。
这很容易吗?
我不知道这是不是你的意思,但也许会有所帮助:
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
这对于非常简单的图像(只有5种颜色)来说就像一个魅力,但也应该适用于更复杂的图像(我没有测试过;在这种情况下,返回的哈希会非常大,所以你可能想在图像上使用量化在使用color_histogram之前)。
一些资源:
color_histogram 量化
我希望这对你有用。 🙂
好。 让我介绍Ruby的库。
使用Camellia, http://camellia.sourceforge.net/examples.html ,您可以使用最突出的颜色标记区域。
不确定这是不是你的意思,但Python PIL有im.histogram()和im.getcolors()函数。 http://effbot.org/imagingbook/image.htm