颜色检测算法 - 我该怎么做? [英] Color detection algorithm - How should I do this?

查看:130
本文介绍了颜色检测算法 - 我该怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



-

我在设计一个颜色检测系统时遇到了一些困难。

基本上,我有一个图像库,我想按颜色排序。因此,如果用户指定按蓝色排序,则最蓝色的图片将显示在结果的顶部,最少的蓝色显示在底部。



问题是图像不是全部一种颜色,所以它在同时做两件事情:



1 - 找到最蓝图片的一部分

2 - 将此蓝色颜色(基于颜色色调和此颜色的量)排序。



我尝试了大约3或4种不同的方法,结果不一样 - 没有一个能正常工作,其中2个是数学算法(在纸上比在实践中更好)。



-



我可以用什么不同的方式来处理整个过程?我可能错过了一些非常明显的方式,它可以工作 - 任何帮助或想法将非常感激:)



-



EDIT:感谢所有回应 - 这是我到目前为止所尝试的:




  • 获得整个图像的平均rgb值并将其与蓝色进行比较。使用归一化的rgb 3空间矢量进行比较,并找到它们之间的距离。


  • 找到主色,并将其与蓝色进行比较(再次使用3个空间矢量距离)。这不行,因为可能有一个大的蓝色部分的图像,而不是最主要的(或在顶部的几个)主色部分。


  • 找到接近蓝色的像素,平均所有这些像素,并将答案与实际蓝色进行比较。


  • 找到接近蓝色的像素



解决方案

p>

低价版本:将图像转换为HSV颜色空间,并为每个像素计算 cos(H - target_hue) 或合理的近似值(对于蓝色, target_hue 将为240度),乘以饱和度,图片。高值是最好的。注意,比蓝色更接近黄色的颜色具有负蓝色,并且黑色,白色和纯灰色具有相等的零蓝色。注意,你真的想要HSV,而不是HSL,在这种情况下,因为HSL中的S不能很好地映射到感知饱和。例如,颜色#f8f8ff(RGB 248,248,255)在HSL中具有100%的饱和度(即,纯蓝色),但是它看起来几乎是白色的。在HSV中相同的颜色具有只有3%的S坐标,这是合理的。



较便宜的版本:将图像转换为CIELAB色彩空间,丢弃L,计算每个像素和目标颜色之间的a * b *空间中的距离,然后计算每个像素的平均值或RMS。低值是最好的。


I'm a bit stuck on designing a color detection system - I can't quite figure out a way to do it easily.

-

Basically, I have a library of images, that I want to sort by color. So if the user specifies 'sort by blue', then the most blue images will appear at the top of the results, with the least blue appearing at the bottom.

The problem is that the images aren't all one color, so it is doing two things at the same time:

1 - finding the bluest part of the image
2 - ranking this blue color (based on color hue and amount of this color).

I've tried about 3 or 4 different approaches, with varying results - none work well though, and 2 of these were quite mathematical algorithms (which all work much better on paper than in practice haha).

-

What different ways could I go about the whole process? I'm probably missing some really obvious ways it could work - any help or ideas would be much appreciated :)

-

EDIT: Thanks for all the responses - here's what I've tried so far:

  • getting the average rgb value for the whole image and comparing it to blue. Comparing was done using normalised rgb 3 space vectors and finding distances between them. This works the least well, an image with no blue could easily appear above an image with partial very strong blue.

  • finding the dominant color and comparing it to blue (again using 3 space vector distances). This didn't work as there might have been a large blue section of the image that wasn't the most (or in the top couple) of dominant color sections.

  • finding pixels that are close to blue, averaging all of these and comparing the answer to actual blue.

  • finding all the pixels that are close to blue, incrementing a count and finding a percentage based on count/total pixels.

解决方案

Two thoughts come to mind:

Cheap version: convert images to HSV color space, and for each pixel compute cos(H - target_hue) or a reasonable approximation (for blue, target_hue would be 240 degrees), multiply by saturation, and average that quantity over all of the pixels in the image. High values are best. Note that colors that are closer to yellow than to blue have "negative blueness", and that black, white, and pure gray have equally "zero blueness". Note that you really want HSV, not HSL, in this situation, because the "S" in HSL doesn't map well to perceptual saturation. For example, the color #f8f8ff (RGB 248, 248, 255) has a saturation of 100% in HSL (i.e. a pure blue), but it looks nearly white. The same color in HSV has an "S" coordinate of only 3%, which is reasonable.

Less cheap version: convert images to CIELAB color space, discard L, and compute the distance in a*b* space between each pixel and the target color, then average or RMS over each pixel. Low values are best.

这篇关于颜色检测算法 - 我该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆