检查颜色相似度的算法
我正在寻找一种算法,可以比较两种 RGB 颜色并生成它们的相似度值(其中相似度意味着“与人类平均感知相似”)。
有什么想法吗?
编辑:
由于我无法再回答,我决定将我的“解决方案”作为对问题的编辑。
我决定在我的应用程序中使用(非常)小的真彩色子集,以便我可以自己处理颜色比较。我使用大约 30 种颜色,并在它们之间使用硬编码距离。
因为它是一个 iPhone 应用程序,所以我使用 Objective-C,其实现或多或少是一个代表下表的矩阵,它显示了颜色之间的距离。
I'm looking for an algorithm that compares two RGB colors and generates a value of their similarity (where similarity means "similar with respect to average human perception").
Any ideas?
EDIT:
Since I cannot answer anymore I decided to put my "solution" as an edit to the question.
I decided to go with a (very) small subset of true-color in my app, so that I can handle comparison of colors by my own. I work with about 30 colors and use hard-coded distances between them.
Since it was an iPhone app I worked with objective-C and the implementation is more or less a matrix representing the table below, which shows the distances between the colors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
RGB 距离 在 欧几里得空间与“平均人类感知”不太相似。
您可以使用 YUV 色彩空间,它考虑到了这个因素:
您还可以使用 CIE 用于此目的的色彩空间。
编辑:
我要提到YUV色彩空间是一种廉价的近似值,可以通过简单的公式计算。但它在感知上并不统一。感知均匀意味着颜色值的相同量的变化应该产生大约相同的视觉重要性的变化。
如果您需要更精确和严格的指标,您一定要考虑 CIELAB 色彩空间或其他感知统一的色彩空间空间(即使没有简单的转换公式)。
RGB distance in the euclidean space is not very similar to "average human perception".
You can use YUV color space, it takes into account this factor :
You can also use the CIE color space for this purpose.
EDIT:
I shall mention that YUV color space is an inexpensive approximation that can be computed via simple formulas. But it is not perceptually uniform. Perceptually uniform means that a change of the same amount in a color value should produce a change of about the same visual importance.
If you need a more precise and rigourous metric you must definitely consider CIELAB color space or an another perceptually uniform space (even if there are no simple formulas for conversion).
我建议使用 CIE94 (DeltaE-1994),据说它可以很好地代表人类颜色感知。我在计算机视觉相关的应用程序中经常使用它,并且我对结果非常满意。
然而,执行这样的比较的计算量相当大:
RGB 到 XYZ
XYZ 到 LAB
两种颜色Diff = DeltaE94(LABColor1,LABColor2)
代码>公式(伪代码):
I would recommend using CIE94 (DeltaE-1994), it's said to be a decent representation of the human color perception. I've used it quite a bit in my computer-vision related applications, and I am rather happy with the result.
It's however rather computational expensive to perform such a comparison:
RGB to XYZ
for both colorsXYZ to LAB
for both colorsDiff = DeltaE94(LABColor1,LABColor2)
Formulas (pseudocode):
这里有一篇关于颜色距离主题的精彩文章:
http://www.compuphase.com/cmetric.htm
如果该资源消失了作者的结论是可以使用此公式(在 C 代码中)实现两种 RGB 颜色之间距离的最佳低成本近似。
There's an excellent write up on the subject of colour distances here:
http://www.compuphase.com/cmetric.htm
In case that resource disappears the author's conclusion is that the best low-cost approximation to the distance between two RGB colours can be achieved using this formula (in C code).
人类对色度的感知比对强度的感知弱。
例如,在商业视频中,YCbCr/YPbPr 色彩空间(也称为 Y'UV)会降低色度信息的分辨率,但保留亮度 (Y)。在数字视频压缩中,例如 4:2:0 和 4:2:2,由于感知相对较弱,因此会降低色度比特率。
我相信您可以计算一个距离函数,该距离函数的优先级高于亮度 (Y),而优先级低于色度。
此外,在低强度下,人类视觉几乎是黑白的。因此,优先级函数是非线性的,因为对于低亮度 (Y),您对色度的权重越来越小。
更科学的公式:http://en.wikipedia.org/wiki/Color_difference
Human perception is weaker in chroma than intensity.
For example, in commercial video, the YCbCr/YPbPr color spaces (also called Y'UV) reduces the resolution of the chroma info but preserves the luma (Y). In digital video compression such as 4:2:0 and 4:2:2 reduces the chroma bitrate due to relatively weaker perception.
I believe that you can calculate a distance function giving higher priority over luma (Y) and less priority over chroma.
Also, under low intensity, human vision is practically black-and-white. Therefore, the priority function is non-linear in that for low luma (Y) you put less and less weight on chroma.
More scientific formulas: http://en.wikipedia.org/wiki/Color_difference
颜色感知不是欧几里得的。任何距离公式都既足够好,同时又很糟糕。任何基于欧几里得距离(RGB、HSV、Luv、Lab...)的测量对于相似的颜色都足够好,显示水绿色接近青色。但对于非接近值来说,它是任意的。例如,红色更接近绿色还是更接近蓝色?
来自 Charles Poynton 的颜色常见问题解答:
Color perception is not Euclidean. Any distance formula will be both good enough and terrible at the same time. Any measure based on Euclidean distance (RGB, HSV, Luv, Lab, ...) will be good enough for similar colors, showing aqua being close to teal. But for non-close values it gets to be arbitrary. For instance, is red closer to green or to blue?
From Charles Poynton's Color FAQ:
RGB 立方体中的颜色相似度通过欧几里得距离来测量(使用毕达哥拉斯公式)。
编辑:再想一想,对于大多数其他色彩空间来说也应该如此。
Color similarity in the RGB cube is measured by the euclidean distance (use pythagoras formula).
EDIT: On a second thought, this should be true for most other color spaces too.