Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to check similarity of colors

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.

enter image description here

like image 983
Kai Huppmann Avatar asked Mar 22 '11 13:03

Kai Huppmann


People also ask

What is similarity algorithm?

Similarity algorithms compute the similarity of pairs of nodes based on their neighborhoods or their properties. Several similarity metrics can be used to compute a similarity score. The Neo4j GDS library includes the following similarity algorithms: Node Similarity. Filtered Node Similarity.

How do you find the difference between two colors?

In order to measure the difference between two colors, the difference is assigned to a distance within the color space. In an equidistant-method color space, the color difference ∆E can be determined from the distance between the color places: ΔE = √ (L*₁-L*₂)² + (a*₁-a*₂)² + (b*₁-b*₂)².

How do you compare colors?

The most common method would be a visual color comparison by looking at two physical color samples side by side under a light source. Color is very relative, so you can compare colors in terms of the other color across dimensions such as hue, lightness and saturation (brightness).

How do you compare two RGB values?

If you have two Color objects c1 and c2 , you can just compare each RGB value from c1 with that of c2 . int diffRed = Math. abs(c1. getRed() - c2.


1 Answers

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 :

 |  Y' |     |  0.299     0.587    0.114   | | R |  |  U  |  =  | -0.14713  -0.28886  0.436   | | G |  |  V  |     |  0.615    -0.51499 -0.10001 | | B | 

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).

like image 126
Ghassen Hamrouni Avatar answered Sep 27 '22 22:09

Ghassen Hamrouni