thomasp85 / farver

High Performance Colourspace Manipulation in R
https://farver.data-imaginist.com
Other
125 stars 14 forks source link

CMC distance is weird #45

Closed jmw86069 closed 2 months ago

jmw86069 commented 2 months ago

While testing the different distance metrics... I think the "CMC" implementation may have a problem. (This not so urgent to me, the other metrics seem fairly good. But this CMC method seems incorrect, unless I'm doing something wrong.)

Test case is to calculate distance between a blue "#007FFF" hex color, versus all R colors(), then sort for lowest distance. The color with lowest CMC distance is darkorange3. Fwiw the test works well with other distance metrics. I tested a bunch of colors, across all metrics, etc. CMC results consistently resemble an artistic mosaic of random colors. (I mean, that might also be useful, but for different reasons!)

Here is the test case:

ref_colors <- colors();
names(ref_colors) <- ref_colors
fdists <- farver::compare_colour(farver::decode_colour("#007FFF", to="lch"),
   farver::decode_colour(ref_colors, to="lch"),
   method="cmc",
   to_space="lch",
   from_space="lch")[1, ]
head(fdists[order(fdists)])

Output:

    darkorange3      violetred2    mediumorchid   mediumorchid3 mediumslateblue      royalblue1 
          0.482           0.542           0.686           1.078           1.476           1.573

Quick plot of the first 6 colors (the first point is the input blue, the next 6 are colors with lowest CMC distance):

plot(x=1:7,
   y=c(0, head(fdists[order(fdists)])),
   pch=20, cex=5, col=c("#007FFF", head(ref_colors[order(fdists)])))
image

Best I could do is find an online calculator to confirm that these two colors are not similar (they are not): http://colormine.org/delta-e-calculator/cmc

I don't think this is the bug from #21, but I did not look in detail.

thomasp85 commented 2 months ago

When I created farmer I took the color comparison implementations at face value from the library I used. Looking at it now I can see that it is pretty bad 😬