0

I'm working on a pixel game that has a limited palette, but lighting and translucency can cause colors to go out of the palette. To make the overall picture uniform, I need a color approximation algorithm with low time complexity.

I've searched about how to find the differences between colors, and find that the distance between colors is not consistent with the distance of their color space coordinates. So I may need a way to optimize the distance finding algorithm for non-uniform spaces, but I'm completely confused about it.

This project is an Webapp game which run on browser, but at this stage it is only planned to be compatible with electron.

凌世雍
  • 47
  • 3
  • 1
    see [Effective gif/image color quantization?](https://stackoverflow.com/a/30265253/2521214) on how to construct palette that best fits your image when its not enough use also [dithering](https://stackoverflow.com/a/36820654/2521214) ... back to your question the simplest metrics is use euclidean distance directly on `(r1,g1,b1) - (r0,g0,b0)` like it would be 3D coordinates ... if you want something more robust use HSV see [RGB value base color name](https://stackoverflow.com/a/37476754/2521214) it contains both RGB and HSV distances ... – Spektre May 10 '22 at 07:14
  • The color difference algorithms described on [Wikipedia](](https://en.wikipedia.org/wiki/Color_difference) ) uses not RGB but LAB, beacuse LAB is more closer to the color space of human eyes. LAB is closer to the three-dimensional polar coordinate system than the Cartesian coordinate system, so `(r1,g1,b1) - (r0,g0,b0)` which fit Cartesian coordinate system doesn't work with LAB... – 凌世雍 May 11 '22 at 02:44
  • If you look at the link in your comment for LAB (CIE76) they also use euclidean distance they just call coordinates `L,a,b` instead of `r,g,b`... in some of the distances there they sometimes scale the coordinates but still use euclidean distance ... The only case where it does not work I know of is HSV where angles are involved so you need to take crossing periods cases into account ... – Spektre May 11 '22 at 06:20

0 Answers0