You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
- Overview
- Functions
- Examples
- Version History
- Reviews (15)
- Discussions (9)
Editor's Note: This file was selected as MATLAB Central Pick of the Week
One function converts between RGB and color names, in both directions.
The function COLORNAMES accepts either RGB values or color names as its inputs, and returns the color names and RGB values from the palette of your choice. The palette is selected by the first input, the trailing inputs are either color names or RGB values:
- Input color name matching is case-insensitive with optional spaces, except for some palettes where whitespace or CamelCase is significant. Diacritics and other special characters are optional.
- Input RGB are matched to the closest palette colors using one of a number of standard color difference metrics. The supported color differences are: CIEDE2000, OkLab, DIN99, CIE94:1, CIE94:2 (default), CIE76 (i.e. CIELAB), CMC2:1, CMC1:1, and RGB.
For more information on color difference metrics: https://en.wikipedia.org/wiki/Color_difference
Whether matching color names or RGB, COLORNAMES always returns the same two output arguments:
- the color names (string array, or cell array of char vectors).
- a numeric array of the corresponding RGB values.
A list of the available palettes is returned by calling COLORNAMES with no inputs. A summary of all palettes is printed by calling COLORNAMES with no inputs and no outputs.
Suggestions of interesting palettes (of named colors) are very welcome!
Bonus Functions
- COLORNAMES_CUBE shows palette colors in a 3D cube. The supported colorspaces: Lab, LCh, DIN99, HSV, OKLab, XYZ, and RGB.
- COLORNAMES_VIEW shows palette colors in 2D axes, and sorting them by various colorspace dimensions (e.g. Lab, XYZ, YUV, HSV, or RGB) or alphanumerically by color name.
- COLORNAMES_DELTAE creates a figure comparing the color difference metrics.
Examples
>> palettes = colornames()
palettes =
'Alphabet'
'AmstradCPC'
'AppleII'
'Bang'
'BS381C'
'CGA'
'Crayola'
'CSS'
'dvips'
'Foster'
'HTML4'
'ISCC'
'Kelly'
'LeCorbusier'
'MacBeth'
'MATLAB'
'Natural'
'OsXCrayons'
'PWG'
'R'
'RAL'
'Resene'
'Resistor'
'SherwinWilliams'
'SVG'
'Tableau'
'Thesaurus'
'Trubetskoy'
'Wada'
'Werner'
'Wikipedia'
'Wolfram'
'X11'
'xcolor'
'xkcd'
>> colornames('Natural') % all color names for one palette
ans =
'Black'
'Blue'
'Green'
'Red'
'White'
'Yellow'
>> [names,rgb] = colornames('HTML4','blue','RED','Teal','olive')
names =
'Blue'
'Red'
'Teal'
'Olive'
rgb =
0 0 1.0000
1.0000 0 0
0 0.5020 0.5020
0.5020 0.5020 0
>> colornames('HTML4',[0,0.5,1;1,0.5,0]) % default deltaE = CIE94:2
ans =
'Blue'
'Red'
>> colornames('HTML4',[0,0.5,1;1,0.5,0],'rgb') % specify deltaE
ans =
'Teal'
'Olive'
>> colornames("MATLAB",'c','m','y','k')
ans =
"Cyan"
"Magenta"
"Yellow"
"Black"
>> [names,rgb] = colornames('MATLAB');
>> compose('%s %d %d %d',char(names),rgb)
ans =
'Black 0 0 0'
'Blue 0 0 1'
'Cyan 0 1 1'
'Green 0 1 0'
'Magenta 1 0 1'
'Red 1 0 0'
'White 1 1 1'
'Yellow 1 1 0'
Cite As
Stephen23 (2024). Convert between RGB and Color Names (https://www.mathworks.com/matlabcentral/fileexchange/48155-convert-between-rgb-and-color-names), MATLAB Central File Exchange. Retrieved .
Requires
- MATLAB
MATLAB Release Compatibility
Created with R2010b
Compatible with R2009b and later releases
Platform Compatibility
Windows macOS Linux
Categories
- MATLAB > Graphics > Formatting and Annotation > Colormaps >
Find more on Colormaps in Help Center and MATLAB Answers
Tags Add Tags
alphabet bang cga cie76 cie94 ciede2000 cielab cmc21 cmclc color database color difference color matching color name color thesaurus colormap colorname colorname database colorscheme crayola css css2rgb database deltae diacritic din99 dvips english2rgb fuzzy lookup fuzzy match fuzzycolor hsv html html2rgb html4 image processing iscc kelly lab lookup macbeth match matlab maximally distinct name2rgb named colors oklab pick of the week potw r ral resene rgb rgb2css rgb2english rgb2html rgb2name rgb2svg rgb2w3c sherwin-williams sundberg svg svg2rgb w3c w3c2rgb wolfram x11 xcolor xkcd xyz yuv
Acknowledgements
Inspired by: rgb.m, name2rgb, Color name identification: fuzzycolor, str2rgb, GETRGB (v1.0), rgb2name, GNU Emacs Color matrix, RGB.m, RGB triple of color name, version 2, Color Checker Chart, CubeHelix Colormap Generator: Beautiful and Versatile!, ColorBrewer: Attractive and Distinctive Colormaps, Intuitive RGB color values from XKCD, rgbmap color maps, alphabet, generate_ishihara(image_name, varargin), colors(name), rgb2map, color, Color segmentation by Delta E color difference
Inspired: Maximally Distinct Color Generator, colorpicker, MatPlotLib Perceptually Uniform Colormaps, Message Logger
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Learn About Live Editor
- colornames
- colornames_cube
- colornames_deltaE
- colornames_view
- COLORNAMES Examples
Version | Published | Release Notes | |
---|---|---|---|
6.1.3 | * Error message improvements | Download | |
6.1.2 | * fix description bullet points | Download | |
6.1.1 | * Correct description. | Download | |
6.1.0 | - Add palettes LeCorbusier, OsxCrayons, PWG, Wada, Werner. | Download | |
6.0.0 | * Accept STRING class text inputs. | Download | |
5.0.1 | Add notes on how to add a new color palette. | Download | |
5.0.0 | * Faster color name matching algorithm. Also more flexible, e.g.: | Download | |
4.0.1 | * Improve layout of palette descriptions and error messages. | Download | |
4.0.0 | * Simplify .mat file structure. | Download | |
3.6.0 | * Add DIN99 colorspace for viewing and deltaE calculation. | Download | |
3.5.3 | * Add "Thesaurus" and "Tableau" palettes. | Download | |
3.5.2.1 | * Improve online description. | Download | |
3.5.2 | * Remove non-ASCII characters from file. | Download | |
3.5.1 | * Fixed missing variable in COLORNAMES_CUBE | Download | |
3.5.0.0 | * VIEW: show RGB value with click on color name. | Download | |
3.4.0.0 | * Change Lab illuminant to D65. | Download | |
3.3.0.0 | * Add AmstradCPC palette. | Download | |
3.2.0.0 | * Documentation changes. | Download | |
3.1.0.0 | * Add CIEDE2000 deltaE color distance calculation. | Download | |
3.0.0.0 | * Total rewrite of the RGB matching algorithm. | Download | |
2.1.0.0 | * Much more robust string matching using Levenshtein distance to pick closest colorname (Wagner–Fischer algorithm). | Download | |
2.0.0.0 | * Add lots of colorschemes. | Download | |
1.2.0.0 | * Add Alphabet and Kelly colorschemes. | Download | |
1.1.0.0 | - Downloadable as toolbox |
| |
1.0.0.0 | Download |
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office