我想得到图像最突出的颜色,语言可以是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
quantize
我希望这对你有用。:)
关于python - 图像颜色识别,一般颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4911066/