有没有一种简单的方法来比较两种颜色彼此的接近程度

时间:2022-03-03 12:32:46

Is there a way to compare how close two colors are to each other? If to say both of them are blue.
At the moment the way that we compare them is to manually assign each possible color to a color family(red, green, blue...). And then just compare the strings :)
But surely that manual task can be assigned to a neat little algorithm.

有没有办法比较两种颜色相互接近的程度?如果说他们俩都是蓝色的。目前我们比较它们的方法是手动将每种可能的颜色分配给颜色系列(红色,绿色,蓝色......)。然后只是比较字符串:)但是肯定可以将手动任务分配给一个简洁的小算法。

3 个解决方案

#1


Delta-e, is a single number that represents the perceived 'distance' between two colors. The lower the number, the more similar the colors are to the human eye.

Delta-e是表示两种颜色之间感知的“距离”的单个数字。数字越低,人眼的颜色越相似。

There are a few different ways to calculate it...CIE76 (aka CIE 1976 or dE76) being the most popular.

有几种不同的计算方法...... CIE76(又名CIE 1976或dE76)是最受欢迎的。

Each one goes about things in a different way, but for the most part they all require you to convert to a better (for comparison) color model than RGB.

每一个都以不同的方式处理事物,但是大多数情况下它们都需要转换为比RGB更好的(用于比较)颜色模型。

For CIE76 you basically just convert your colors to the LAB color space, then compute the 3 dimensional distance between them.

对于CIE76,您基本上只需将颜色转换为LAB颜色空间,然后计算它们之间的3维距离。

Wikipedia has all the formulae: http://en.wikipedia.org/wiki/Color_difference

*有所有公式:http://en.wikipedia.org/wiki/Color_difference

You can check your work with online color calculators:

您可以使用在线颜色计算器检查您的工作:

#2


You probably want to convert the colors to an HSL model (Hue, Saturation, Lightness) and then compare the values within thresholds in the order HSL. If the hue is within a tolerance deemed as "close", then check the "closeness" of the saturation, and then the lightness.

您可能希望将颜色转换为HSL模型(色调,饱和度,亮度),然后按HSL顺序比较阈值内的值。如果色调在被视为“接近”的容差范围内,则检查饱和度的“接近度”,然后检查亮度。

#3


I'm not sure of any algorithms, you may want to consider converting RGB (Red, Green, Blue) values in to HSB (Hue, Saturation, Brightness).

我不确定是否有任何算法,您可能需要考虑将RGB(红色,绿色,蓝色)值转换为HSB(色调,饱和度,亮度)。

Hue is essentially "color", so you can compare simply on how close the Hue values are.

Hue本质上是“颜色”,因此您可以简单地比较Hue值的接近程度。

See http://en.wikipedia.org/wiki/HSV_color_space

#1


Delta-e, is a single number that represents the perceived 'distance' between two colors. The lower the number, the more similar the colors are to the human eye.

Delta-e是表示两种颜色之间感知的“距离”的单个数字。数字越低,人眼的颜色越相似。

There are a few different ways to calculate it...CIE76 (aka CIE 1976 or dE76) being the most popular.

有几种不同的计算方法...... CIE76(又名CIE 1976或dE76)是最受欢迎的。

Each one goes about things in a different way, but for the most part they all require you to convert to a better (for comparison) color model than RGB.

每一个都以不同的方式处理事物,但是大多数情况下它们都需要转换为比RGB更好的(用于比较)颜色模型。

For CIE76 you basically just convert your colors to the LAB color space, then compute the 3 dimensional distance between them.

对于CIE76,您基本上只需将颜色转换为LAB颜色空间,然后计算它们之间的3维距离。

Wikipedia has all the formulae: http://en.wikipedia.org/wiki/Color_difference

*有所有公式:http://en.wikipedia.org/wiki/Color_difference

You can check your work with online color calculators:

您可以使用在线颜色计算器检查您的工作:

#2


You probably want to convert the colors to an HSL model (Hue, Saturation, Lightness) and then compare the values within thresholds in the order HSL. If the hue is within a tolerance deemed as "close", then check the "closeness" of the saturation, and then the lightness.

您可能希望将颜色转换为HSL模型(色调,饱和度,亮度),然后按HSL顺序比较阈值内的值。如果色调在被视为“接近”的容差范围内,则检查饱和度的“接近度”,然后检查亮度。

#3


I'm not sure of any algorithms, you may want to consider converting RGB (Red, Green, Blue) values in to HSB (Hue, Saturation, Brightness).

我不确定是否有任何算法,您可能需要考虑将RGB(红色,绿色,蓝色)值转换为HSB(色调,饱和度,亮度)。

Hue is essentially "color", so you can compare simply on how close the Hue values are.

Hue本质上是“颜色”,因此您可以简单地比较Hue值的接近程度。

See http://en.wikipedia.org/wiki/HSV_color_space