问题
I was looking to convert given RGB values to the actual colour name in Python or atleast the close match of the colour.
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.
回答1:
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.
From the documentation,
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.
Example provided:
>>> rgb_to_name((0, 0, 0))
'black'
来源:https://stackoverflow.com/questions/51354637/rbg-values-to-colour-name-python