Monday, September 12, 2011

The typical Weighted Euclidean color distance values are wrong.

There's a rather common set of weights for Euclidean Color Distance, to better approximate the human eye.

(30*(r1-r2))**2 + (59*(g1-g2))**2 + (11*(b1-b2))**2

30, 59, and 11 for RGB weights.

Well, they seemed rather pulled out of one's ass. And I'm not the first to notice. But, I did bother to code up a routine to compare CIELab to color distance weights and find out, by brute forcing each and every color distance to find out where the weights there should be.

22.216091748149788, 42.88860259783791, 34.895305654012304

Or 22, 43, 35 since we're very likely going with integer math. This is just brute force average best approximation of weighted Euclidean to CIELab.

From the cited Color metric article:

  • Several individuals suggested a weighted Euclidean distance in R'G'B', according to the formula:
    ΔC=3×ΔR2+4×ΔG2+2×ΔB2
    This function has practically the same result as YUV. Its simplicity and speed of calculation make it a better choice than YUV.
  • As explained in the section "gamma correction" below, the perception of brightness by the human eye is non-linear. From the experiments it appears that the curve for this non-linearity is not the same for each colour. The weighted Euclidean distance presented works quite well for the subset of colours where the "red" signal is 128 or more (on a scale of 0-255). For the other half of the full R'G'B' cube, this different weighting produced better results:
    ΔC=2×ΔR2+4×ΔG2+3×ΔB2

 2, 4, 3, are pretty close to my values (they are weights and thus need to be proportional to each other not similar in absolute magnitude). 2/9, 4/9, 3/9 or 22.22, 44.44, 33.33 when you bring the weights up to how many parts I have. So 22.22 vs 22.21...  44.4 vs 42.8 ... 33.3 vs 34.9.

Update:
I also ran the colors for CIELuv.

R G B weights:
0.2753667361197665, 0.3846815980739518, 0.3399516658062818

28, 38, 34

1 comment:

Kay said...

I'm not even going to attempt this one.