Convert RGB color to English color name, like 'green' with Python

后端 未结 4 640
再見小時候
再見小時候 2020-11-30 19:39

I want to convert a color tuple to a color name, like \'yellow\' or \'blue\'

>>> im = Image.open(\"test.jpg\")
>>> n, color = max(im.getcol         


        
4条回答
  •  温柔的废话
    2020-11-30 20:31

    A solution to your problem consists in mapping the RGB values to the HSL color space.

    Once you have the color in the HSL color space you can use the H (hue) component to map it the color. Note that color is a somewhat subjective concept, so you would have to define which ranges of H corresponds to a given color.

提交回复
热议问题