2011-02-06 191 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

我希望這是對你有用。 :)