2011-02-06 263 views

回答

1

我不知道这是你的意思,但也许这将是有益的:

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 quantize

我希望这是对你有用。 :)