# Color difference

The difference or distance between two colors is a metric of interest in color science. It allows quantified examination of a notion that formerly could only be described with adjectives. Quantification of these properties is of great importance to those whose work is color-critical. Common definitions make use of the Euclidean distance in a device independentcolor space.

## . . . Color difference . . .

As most definitions of color difference are distances within a color space, the standard means of determining distances is the Euclidean distance. If one presently has an RGB (Red, Green, Blue) tuple and wishes to find the color difference, computationally one of the easiest is to consider R, G, B linear dimensions defining the color space.

${displaystyle mathrm {distance} ={sqrt {(R_{2}-R_{1})^{2}+(G_{2}-G_{1})^{2}+(B_{2}-B_{1})^{2}}}}$

When the result should be computationally simple as well, it is often acceptable to remove the square root and simply use:

${displaystyle mathrm {distance} ^{2}={(R_{2}-R_{1})^{2}+(G_{2}-G_{1})^{2}+(B_{2}-B_{1})^{2}}}$

This will work in cases when a single color is to be compared to a single color and the need is to simply know whether a distance is greater. If these squared color distances are summed, such a metric effectively becomes the variance of the color distances.

There have been many attempts to weigh RGB values to better fit human perception, where the components are commonly weighted (red 30%, green 59%, and blue 11%), however these are demonstrably worse at color determinations and are properly the contributions to the brightness of these colors, rather than to the degree to which human vision has less tolerance for these colors. The closer approximations would be more properly (for non-linear sRGB, using a color range of 0255):[1]

${displaystyle {begin{cases}{sqrt {2times Delta R^{2}+4times Delta G^{2}+3times Delta B^{2}}}&{bar {R}}$

where:

{displaystyle {begin{aligned}Delta R&=R_{1}-R_{2}\Delta G&=G_{1}-G_{2}\Delta B&=B_{1}-B_{2}\{bar {R}}&={{R_{1}+R_{2}} over 2}\end{aligned}}}

One of the better low-cost approximations, sometimes called “redmean”, combines the two cases smoothly:[1]

{displaystyle {begin{aligned}{bar {r}}&={{R_{1}+R_{2}} over 2},\Delta C&={sqrt {left({2+{{bar {r}} over {256}}}right)times Delta R^{2}+4times Delta G^{2}+left({2+{{255-{bar {r}}} over {256}}}right)times Delta B^{2}}}.end{aligned}}}

There are a number of color distance formulae that attempt to use color spaces like HSV with the hue as a circle, placing the various colors within a three dimensional space of either a cylinder or cone, but most of these are just modifications of RGB; without accounting for differences in human color perception they will tend to be on par with a simple Euclidean metric.