简体   繁体   English

图像颜色识别,一般颜色

[英]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. 我想获得图像最突出的颜色,并且语言可以是python或ruby。

Is this easily done? 这容易做到吗?

Not sure if this is what you mean, but the Python PIL has im.histogram() and im.getcolors() functions. 不确定这是否是您的意思,但是Python PIL具有im.histogram()和im.getcolors()函数。 http://effbot.org/imagingbook/image.htm http://effbot.org/imagingbook/image.htm

OK. 好。 Let me introduce the library for Ruby. 让我介绍Ruby的库。

Using Camellia, http://camellia.sourceforge.net/examples.html , you can label the area with the most prominent color. 使用http://camellia.sourceforge.net/examples.html茶花,您可以用最突出的颜色标记该区域。

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). 对于非常简单的图像(仅5种颜色)来说,这就像一个魅力,但对于更复杂的图像也应该起作用(我没有测试过;在这种情况下,返回的哈希值会很大,因此您可能要对图像使用量化在使用color_histogram之前)。

Some resources : 一些资源:

color_histogram quantize color_histogram 量化

I hope this was useful to you. 我希望这对您有用。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM