RBG值将颜色命名为Python [英] RBG values to colour name Python

查看:100
本文介绍了RBG值将颜色命名为Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将给定的RGB值转换为Python中的实际颜色名称,或者至少将该颜色匹配.

I was looking to convert given RGB values to the actual colour name in Python or atleast the close match of the colour.

给出值, [50.2862498 72.08996663 70.66173433]我希望能够将这些值与[185.89894822 186.47802004 185.94613642]区分为绿色.

Given the values, [50.2862498 72.08996663 70.66173433] I want to be able to distinguish these values from [185.89894822 186.47802004 185.94613642] as a shade of green.

原因我要做的是从图像中去除绿色阴影.

Reason I need to do that is to remove shades of green from an image.

推荐答案

在此处查看webcolors python包:

Look at webcolors python package here: https://pypi.org/project/webcolors/1.3/. It looks like the rgb_to_name(rgb_triplet, spec='css3') function does exactly what you want.

从文档

将适用于rgb()颜色三元组的3元整数转换为其对应的归一化颜色名称(如果存在). 可选的关键字参数spec确定使用哪个规范的颜色名称列表;有效值为html4,css2,css21和css3,默认值为css3. 如果没有匹配的名称,则会引发ValueError.

Convert a 3-tuple of integers, suitable for use in an rgb() color triplet, to its corresponding normalized color name, if any such name exists. The optional keyword argument spec determines which specification’s list of color names will be used; valid values are html4, css2, css21 and css3, and the default is css3. If there is no matching name, ValueError is raised.

提供了示例:

>>> rgb_to_name((0, 0, 0))
'black'

这篇关于RBG值将颜色命名为Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆