Algorithm to check similarity of colors

algorithmcolorscomparisonrgb

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

Best Answer

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