Methods for quantifying the similarity between two colours?
这个问题可能与人类心理学有关
我正在尝试制作一个使用有限的调色板重新创建位图图像的程序。 我天真地以为我可以简单地找到红色/绿色/蓝色值的平方差,然后用它来量化颜色之间的平方差。 但是在实践中,这似乎效果不佳,红色的阴影与紫色的阴影相匹配,依此类推。
有人对我可以使用的其他比较方法有什么建议吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | int squaredDistance(colour a, colour b) { return (a.r - b.r)*(a.r - b.r) + (a.g - b.g)*(a.g - b.g) + (a.b - b.b)*(a.r - b.b); } int findClosestColour(colour a) //Returns id of colour that most closely matches { int smallestColourDistance = 195075; int colourId = -1; for(int i=0; i<NUMOFCOLOURS; i++) { if( squaredDistance(a, coloursById[i]) < smallestColourDistance) { smallestColourDistance = squaredDistance(a, coloursById[i]); colourId = i; if(smallestColourDistance == 0) break; } } return colourId; } |
这在色彩科学中称为色差,有多种算法可以计算出色差,其中有一些:
- 三角洲E CIE 1976
- Delta E CIE 1994
- 台达E CIE 2000
- 台达E CMC
Bruce Lindbloom有一个计算器,Color提供了矢量化的Python实现。您必须先将RGB值转换为CIE Lab才能使用任何Delta E实现。
还可以在CIECAM02颜色外观模型之上实现可用的色差计算,尤其是CAM02-UCS颜色空间,它是CIECAM02基础颜色空间的更统一版本。
这是一个老问题,但万一有人碰到它...
我有一个类似的问题,我想计算两种随机选择的颜色(前景和背景)之间的差异,以确保前景可读。因此,我进行了研究,并编写了这个小C ++库,该库使用CIE76计算delta-E:
https://github.com/ThunderStruct/Color-Utilities
样品:
1 2 3 4 5 6 | // Colors' Construction ColorUtils::rgbColor c1(1.0f, 1.0f, 1.0f), c2(0.5f, 0.5f, 0.5f); // Calculate Delta-E std::cout << ColorUtils::getColorDeltaE(c1, c2) << '\ '; |
输出