Which is most accurate way to distinguish one of 8 colors?

后端 未结 6 765
星月不相逢
星月不相逢 2021-02-09 06:00

Imagine we how some basic colors:

RED = Color ((196, 2, 51), \"RED\")
ORANGE = Color ((255, 165, 0), \"ORANGE\")
YELLOW = Color ((255, 205, 0), \"YELLOW\")
GREEN         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 06:39

    Short answer: use the Euclidean distance in a device independent color space (source: Color difference article in Wikipedia). Since RGB is device-dependent, you should first map your colors to one of the device-independent color spaces.

    I suggest to convert RGB to Lab*. To quote Wikipedia again:

    Unlike the RGB and CMYK color models, Lab color is designed to approximate human vision.

    Here's a recipe to do the conversion. Once you have the L, a, b values, calculate the Euclidean distance between your color and all the reference colors and choose the closest one.


    Actually, the python-colormath Python module on Google Code (under GPL v3) is capable of converting between many different color spaces and calculates color differences as well.

提交回复
热议问题