比较RGB颜色,使色差比强度和更重要 [英] Compare RGB colors so that color difference is more significant then intensity sum

查看:425
本文介绍了比较RGB颜色,使色差比强度和更重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在图像分析过程中比较颜色时,您很快就会发现您只能使用灰度图像。为什么?因为通常你这样做:

  double average =(color.r + color.g + color.b)/ 3; 

基于grascale平均颜色,我做了一个算法,当它找到一个对象在屏幕上(我使用整个桌面,但很好,这是足够):





按平均颜色搜索花费了67毫秒,而通过完全匹配的像素(蓝框)搜索花费了1.255秒< >! (并且前者在发现第一匹配之后立即终止,而平均颜色算法循环整个图像)。



但是我想提高GUI的精度。在GUI中,红色按钮看起来像蓝色按钮,可能会匹配错误。这就是为什么我实现了色彩敏感的积分图像。现在我发现我不知道如何正确比较颜色和以获得一些真实的颜色差异。



想象你有2数组3个元素。

  //在您要查找的图像上求和的颜色
double sumOnSearchedImage [3] ;
//在当前检查的矩形上的总颜色(在某些循环中,我们不会在这里)
double sumOnBigImage [3];

数组中的每个数字分别表示红色,蓝色和绿色的总和如何比较这些,使 rgb(0,255,255) rgb(255,255,255) > c> c> c> rgb(255,255,255)

解决方案

在度量空间中,rgb(0,255,255)和rgb(255,255,255)之间的距离已经远远大于rgb



<$>



<$> p $ p> |(0,255,255),(255,255,255)| ^ 2 = 255 ^ 2 = 9 * 85 ^ 2
|(170,170,170),(255,255,255)| ^ 2 = 3 * 85 ^ 2

BTW,不要惊讶地发现灰度观看已经足够。良好的设计使得设计师能够使事物a)清晰可见,b)至少对于大约18%的人来说是可见的,因为只有这么多人有颜色看见的问题。 http://www.colour-blindness.com/general/prevalence/ p>

When it comes to comparing colors during image analysis, you'll soon discover that you can just use grayscale image. Why? Because usually you do this:

double average = (color.r+color.g+color.b)/3;

Based on grascale average colors, I made an algorithm that is actually quite satisfying when it comes to find an object on screen (I used whole desktop, but well, this is enough):

Search by average color took 67ms while searching by exact pixel match (blue frame) took 1.255 seconds! (and the former terminated right after finding first match, while the average color algorithm loops whole image).

But I wanted to improve precision on GUI's. In GUI red button looks just like blue button and may be matched wrongly. This is why I implemented color-sensitive integral image. Now I discovered that I don't know how to properly compare the color sums to get some real color difference.

So imagine you have 2 arrays of 3 elements.

//Summed colors on the image you're looking for
double sumOnSearchedImage[3];
//Summed colors on currently checked rectangle (in some loop we'll not bother with here)
double sumOnBigImage[3];

Every number in the arrays represents red, blue and green sum (not average) respectively. How do you compare these so that difference between rgb(0, 255, 255) and rgb(255,255,255) is larger than difference between rgb(170,170,170) and rgb(255,255,255)?

解决方案

In the metric space the distance between rgb(0, 255, 255) and rgb(255,255,255) is already far larger than distance between rgb(170,170,170) and rgb(255,255,255).

Only use not distances themselves, but their squares, for speed.

|(0, 255, 255), (255,255,255)|^2 = 255^2 = 9*85^2
|(170,170,170), (255,255,255)|^2 = 3*85^2

BTW, don't be astonished to find that grayscale seeing is often enough. The good design makes designers to make things a) well visible and b) at least somehow visible for about 18% of people, for just so many have problems with colors seeing. http://www.colour-blindness.com/general/prevalence/

这篇关于比较RGB颜色,使色差比强度和更重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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