File Exchange

image thumbnail

Convert between RGB and Color Names

version 3.5 (199 KB) by

RGB to color name. Color name to RGB. Palletes: CSS, HTML, MATLAB, SVG, X11, xcolor, xkcd,...



View License

One function converts between RGB and color names, in both directions!

The function COLORNAMES accepts either RGB values or colorname strings as its inputs, and returns the color names and RGB values from the palette of your choice. The color palette is selected by the first input, the trailing inputs are either color names or RGB values:

* Input RGB are matched using RGB, CMCl:c, CIE76, CIE94, or CIEDE2000 color difference calculation.
* Input color name matching is case insensitive with optional spaces, except for some schemes where CamelCase is significant.

Whether matching RGB values or color name strings, COLORNAMES has the same two outputs:
1. Cell array of the matched color name strings.
2. Numeric array of the RGB values (a standard MATLAB colormap).

A list of the available palettes is returned by calling COLORNAMES with no inputs.

Three bonus functions are also included:

* COLORNAMES_CUBE shows the colors from any palette in a 3D cube. The cube may be RGB, Lab, LCh, HSV, or XYZ.
* COLORNAMES_VIEW shows the colors from any palette in 2D axes, and sorting them by different color space values (Lab, XYZ, YUV, HSV, or RGB).
* COLORNAMES_DELTAE creates a figure comparing the different color difference calculations (deltaE, e.g. CIEDE2000, CIE94, CIE76, CMCl:c, or RGB). For more information:

Suggestions of useful palettes (with named colors) are very welcome!

### Examples ###

colornames() % list all supported palettes
ans =

colornames('Natural') % all color names for one palette
ans =

[clr,rgb] = colornames('HTML4','blue','red','teal','olive')
clr =
rgb =
0 0 1
1 0 0
0 0.50196 0.50196
0.50196 0.50196 0

colornames('HTML4',[0,0.5,1;1,0.5,0]) % deltaE = CIE94
ans =

colornames('HTML4',[0,0.5,1;1,0.5,0],'rgb') % specify deltaE
ans =

[clr,rgb] = colornames('MATLAB');
[char(strcat(clr,{' '})),num2str(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

ans =

Comments and Ratings (4)

Hao Xie

Jan Studnicka

Saved my thesis, thanks a lot!



* VIEW: show RGB value with click on color name.
* Combine into one resistor palette.
* Allow for negative leading integer.


* Change Lab illuminant to D65.
* Fix bug in camorbit for CUBE.
* Improve help examples.


* Add AmstradCPC palette.
* Match initial letters for palettes Alphabet, MATLAB, and Natural.


* Documentation changes.


* Add CIEDE2000 deltaE color distance calculation.


* Improved HTML documentation.


* Add COLORNAMES_CUBE function.
* Change input argument name from "scheme" to "palette".


* Total rewrite of the RGB matching algorithm.
* Add HTML documentation.


* Much more robust string matching using Levenshtein distance to pick closest colorname (Wagner–Fischer algorithm).
* Rename supplementary function (deltaE viewer) and add default values.


* Add lots of colorschemes.
* Add new fields to .MAT file: <spaces> and <indices>.


* Add Alphabet and Kelly colorschemes.


- Downloadable as toolbox

MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video