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

attributeerror: module 'webcolors' has no attribute 'css3_hex_to_names'
rgb to color
python rgb color
rgb to color name
python colour color
python rgb color wheel
nameerror: name colors is not defined
convert color code to rgb python

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

>>> im = Image.open("test.jpg")
>>> n, color = max(im.getcolors(im.size[0]*im.size[1]))
>>> print color
(119, 172, 152)

Is there a simple way in python to do this?

It looks like webcolors will allow you to do this:

rgb_to_name(rgb_triplet, spec='css3')

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; valid values are html4, css2, css21 and css3, and the default is css3.

Example:

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

it is vice-versa-able:

>>> name_to_rgb('navy')
(0, 0, 128)
To find the closest colour name:

However webcolors raises an exception if it can't find a match for the requested colour. I've written a little fix that delivers the closest matching name for the requested RGB colour. It matches by Euclidian distance in the RGB space.

import webcolors

def closest_colour(requested_colour):
    min_colours = {}
    for key, name in webcolors.css3_hex_to_names.items():
        r_c, g_c, b_c = webcolors.hex_to_rgb(key)
        rd = (r_c - requested_colour[0]) ** 2
        gd = (g_c - requested_colour[1]) ** 2
        bd = (b_c - requested_colour[2]) ** 2
        min_colours[(rd + gd + bd)] = name
    return min_colours[min(min_colours.keys())]

def get_colour_name(requested_colour):
    try:
        closest_name = actual_name = webcolors.rgb_to_name(requested_colour)
    except ValueError:
        closest_name = closest_colour(requested_colour)
        actual_name = None
    return actual_name, closest_name

requested_colour = (119, 172, 152)
actual_name, closest_name = get_colour_name(requested_colour)

print "Actual colour name:", actual_name, ", closest colour name:", closest_name

Output:

Actual colour name: None , closest colour name: cadetblue

RGB (Red Green Blue) Definition, I want to convert a color tuple to a color name, like 'yellow' or 'blue' >>> im = Image.open("test.jpg") >>> n, color  It looks like webcolors will allow you to do this:. rgb_to_name(rgb_triplet, spec='css3') 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; valid values are html4, css2, css21 and css3, and the default is css3.

There is a program called pynche which can change RGB to colour name in English for Python.

You can try to use the method ColorDB.nearest() in ColorDB.py which can do what you want.

You can find more information about this method here : ColorDB Pynche

Convert RGB color to English color name, like 'green' with Python, Problem is that people do not really agree on a 1:1 mapping of color names. But yes such tools exists, this is a simple nearest neighborhood test. You could use  RGB (Red Green Blue) Color Model is an Additive Color Model (if you don't add anything, it's black), used for screens. Complementary Color: that is on the opposite side of the RGB color wheel, with opposite hue: Websafe (255, 102, 0) Greyscale (137, 137, 137) closest color on the list of 216 colors that were safe for old 256-color screens

Convert RGB, Hex or any other color format to "Standard Color , Color, Color. name. (R,G,B), Hex. Black, (0,0,0), #000000. White, (255,255,255), #FFFFFF. Red, (255,0,0), #FF0000. Lime, (0,255,0), #00FF00. Blue, (0,0,255), #  We've created an HTML color converter for you to know all of your color values, RGB, HEX, HSL, HWB, CMYK and NCOL. Get your Html Color codes with our color tools, HEX code, RGB, RGBA, HSL and HSLA values, including HSV, HWB and CMYK.

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.

RGB to Hex color converter, Color Converter. ❮ Previous Next ❯. Enter a Color: name, hex, rgb, hsl, hwb,  RGB and COLOR search engine find similar colors in different collections. All you need to match your RGB and color data with paint, ink, color standards and commercial color collections.

Color Converter, Description of Columns. Color Name, Names of colors as given in the various sources I used to create this table. See "Credits" below. Color conversion. Color code converter. Color codes chart. Color conversions. Color code converter. HEX value is 6 digits (rrggbb). RGB values are in range of 0..255.

RGB to Color Name Mapping(Triplet and Hex), Web colors are colors used in displaying web pages on the World Wide Web, and the methods for describing and specifying those colors. Colors may be specified as an RGB triplet or in hexadecimal format (a hex triplet) or according to their common English names in some cases. Web-based tools specifically for converting color values are also available. An RGB color value is used in HTML or CSS to define a color on a web page. The RGB color value is a mix of three color components. R is red, G is Green, and B is blue. Each of the color components (R, G, and B) is a value between 0 and 255 in decimal. What is a Decimal color value (Dec)? A Decimal color value is used as an alternative to the

Web colors, A library for working with sRGB color specifications as used in HTML and CSS. Convert a color name to a 3-tuple of integers suitable for use in an rgb() triplet  RGB and COLOR search engine match color data to commercial colors. All you need to match your RGB and color data with paint, ink, color standards and commercial color collections.

Comments
  • I think I found the droids you're looking for... pypi.python.org/pypi/webcolors/…
  • I don't know if there's already a solution to this, but any such mapping will necessarily be heuristic and entirely subjective... Interesting question, though!
  • Do you want precise colour names or approximations? For example, "green" is (obviously) (0,255,0). What would you like color((0,254,0)) to be?
  • @WillVousden not necessarily: some colours have official names.
  • Do you want the colors to be the same colors that are used when setting a font color in HTML (e.g., <font color = "red">Sample text</font>)?
  • Provided link doesn't work anymore. Here you can find file ColorDB.py.
  • You can have a greater accuracy using the CSS4 list, which is provided by matplotlib.colors. For example import matplotlib.colors as mc and mycss4list = mc.CSS4_COLORS