比较c#中的RGB颜色 [英] Compare RGB colors in c#

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

问题描述

我试图找到一种方法来比较两种颜色,以找出它们的相似程度.我似乎找不到有关该主题的任何资源,所以我希望能在这里得到一些指点.

I'm trying to find a way to compare two colors to find out how much they are alike. I can't seem to find any resources about the subject so I'm hoping to get some pointers here.

理想情况下,我想得到一个分数,表明他们有多相似.例如,0 到 100,其中 100 是相等的,0 是完全不同的.

Idealy, I would like to get a score that tells how much they are alike. For example, 0 to 100, where 100 would be equal and 0 would be totally different.

谢谢!

从答案中更多地了解颜色我明白我的问题有点含糊.我会尽量解释我需要这个的目的.

Getting to know a bit more about colors from the answers I understand my question was a bit vague. I will try to explain what I needed this for.

我有一个 800x600 大小的应用程序窗口的像素数据(位置和颜色),因此我可以通过检查每个 x 间隔来确定某个窗口是否打开.

I have pixeldata (location and color) of an application window at 800x600 size so I can find out if a certain window is open or not by checking every x-interval.

但是,一旦应用程序调整大小(内容被缩放,而不是移动),此方法就会失败.我可以计算像素移动的位置,但由于四舍五入和抗锯齿,颜色可能会略有不同.

However, this method fails as soon as the application is resized (the contents are scaled, not moved). I can calculate where the pixels move, but because of rounding and antialising the color can be slightly different.

在这种情况下,Pieter 的解决方案对我来说已经足够好了,尽管所有其他回复也非常有帮助,所以我只是为每个人点赞.从专业的角度来看,我确实认为ColorEye的答案是最准确的,所以我将其标记为答案.

Pieter's solution was good enough for me in this case, although all other responses were extremely helpfull as well, so I just upvoted everyone. I do think that ColorEye's answer is the most accurate when looking at this from a professional way, so I marked it as the answer.

推荐答案

您要查找的内容称为 Delta-E.

What you are looking for is called Delta-E.

http://www.colorwiki.com/wiki/Delta_E:_The_Color_Difference

它是LAB色彩空间中两种颜色之间的距离.据说人眼无法分辨1 DeltaE以下的颜色(我发现我的眼睛能分辨出1 DeltaE以下的颜色差异,每个人都不一样.)

It is the distance between two colors in LAB color space. It is said that the human eye cannot distinguish colors below 1 DeltaE (I find that my eyes can find differences in colors below 1 DeltaE, each person is different.)

'色差'有4个公式.

  • Delta E (CIE 1976)
  • Delta E (CIE 1994)
  • Delta E (CIE 2000)
  • Delta E (CMC)

检查此站点上的数学链接:

Check the math link on this site:

所以正确的答案是使用给定的公式将 RGB 转换为 LAB,然后使用 DeltaE 1976 来确定颜色的差异".结果为 0 表示颜色相同.任何大于 0 的值都可以通过大多数人无法区分 1 或更小的 delta e"规则来判断.

So the proper answer is to convert your RGB to LAB using the formula given, then use DeltaE 1976 to determine the 'difference' in your colors. A result of 0 would indicate identical colors. Any value higher than 0 could be judged by the rule 'A delta e of 1 or less is indistinguishable by most people'.

这篇关于比较c#中的RGB颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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