Color Matching Algorithm

I am looking for an algorithm that compares two RGB colors and generates a value for their similarity (where the similarity means "similar to the average human perception").

Any ideas?

EDIT

Since I can no longer answer, I decided to put my "solution" as an editing question.

I decided to go with a (very) small subset of true color in my application so that I can handle the color comparison as I see fit. I work with about 30 colors and use hardcoded distances between them.

Since this is an application for the iPhone, 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.

enter image description here

+71
comparison algorithm colors rgb
Mar 22 2018-11-22T00:
source share
6 answers

The distance of RGB in Euclidean space is not very "similar to ordinary human perception"

You can use the YUV color space, it takes this factor into account:

enter image description here

You can also use the CIE color space.

EDIT:

I mentioned that the YUV color space is an inexpensive approximation that can be calculated using simple formulas. But this is not perceived uniformly. A uniformly perceived form means that a change in the same value in the color value should lead to a change in approximately the same visual importance. If you need a more accurate and rigorous metric, you should definitely consider the CIELAB color space or other perceptually homogeneous space (even if there are no simple formulas for the transformation).

+52
Mar 22 2018-11-22T00:
source share

I would recommend using CIE94 (DeltaE-1994), he said that this is a decent idea of ​​the perception of human perception. I used it very little in computer vision applications, and I am very pleased with the result.

However, however, a rather expensive calculation for such a comparison:

  • RGB to XYZ for both colors
  • XYZ to LAB for both colors
  • Diff = DeltaE94(LABColor1,LABColor2)

Formulas (pseudo-code):

+14
Sep 08 '14 at 14:19
source share

Human perception is weaker in color than intensity.

For example, in commercial video, YCbCr / YPbPr color spaces (also called Y'UV) reduce the resolution of color information, but retain brightness (Y). In digital video compression, such as 4: 2: 0 and 4: 2: 2, the color bitrate is reduced due to the relatively poor perception.

I believe that you can calculate the distance function giving a higher priority over luminance (Y) and lower priority for color.

In addition, at low intensity, human vision is almost black and white. Therefore, the priority function is non-linear in that for low brightness (Y) you put less and less weight on the color.

More scientific formulas: http://en.wikipedia.org/wiki/Color_difference

+11
Mar 22 2018-11-11T00:
source share

Here's a great entry on the theme of color distances: http://www.compuphase.com/cmetric.htm

If the resource disappears, the author concludes that the best inexpensive approximation to the distance between two RGB colors can be achieved using this formula (in code).

 typedef struct { unsigned char r, g, b; } RGB; double ColourDistance(RGB e1, RGB e2) { long rmean = ( (long)e1.r + (long)e2.r ) / 2; long r = (long)e1.r - (long)e2.r; long g = (long)e1.g - (long)e2.g; long b = (long)e1.b - (long)e2.b; return sqrt((((512+rmean)*r*r)>>8) + 4*g*g + (((767-rmean)*b*b)>>8)); } 
+4
Dec 03 '16 at 16:43
source share

Perception of color is not Euclidean. Any distance formula will be both good enough and terrible at the same time. Any measure based on the Euclidean distance (RGB, HSV, Luv, Lab, ...) will be good enough for such colors, showing that the aqua is close to tick. But for non-close values, it becomes arbitrary. For example, is red closer to green or blue?

From Charles Poynton Color FAQs :

XYZ and RGB systems are far from demonstrating uniformity of perception. The search for transforming XYZ into a reasonably perceptually homogeneous space has consumed 10 years or more at CIE and, in the end, no system could be consistent.

+3
Mar 23 2018-11-11T00:
source share

The color absorption in an RGB cube is measured by the Euclidean distance (use the pythagoras formula).

EDIT: The second time this should be true for most other color spaces.

-four
Mar 22 2018-11-22T00:
source share



All Articles