Convert between RGB and Color Names

バージョン 6.1.2 (496 KB) 作成者: Stephen23
RGB to color name. Color name to RGB. Supports many palettes: CSS, dvips, HTML, MATLAB, RAL, SVG, X11, xcolor, xkcd,...

ダウンロード 2.8K 件

更新 2022/9/8

ライセンスの表示

編集メモ: 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 RGB are matched to the closest palette colors using CIEDE2000, CIE94:1, CIE94:2 (default), CIE76 (i.e. Lab), CMC, DIN99, OKLab, or RGB color difference (deltaE) metrics.
  • Input color name matching is case-insensitive with optional spaces, except for some palettes where whitespace or CamelCase is significant.
Whether matching color names or RGB, COLORNAMES always returns the same two output arguments:
  1. the color names (string array, or cell array of char vectors).
  2. a numeric array of the corresponding RGB values.
A list of the available palettes is returned by calling COLORNAMES with no inputs.
Suggestions of interesting palettes (with named colors) are very welcome!
Bonus Functions
  • COLORNAMES_CUBE shows palette colors in a 3D cube (Lab, LCh, DIN99, HSV, OKLab, XYZ, or RGB).
  • COLORNAMES_VIEW shows palette colors in 2D axes, and sorting them by various color space dimensions (Lab, XYZ, YUV, HSV, or RGB).
  • COLORNAMES_DELTAE creates a figure comparing the different color difference calculations (CIEDE2000, CIE94, CIE76, DIN99, CMC, OKLab, or RGB). For more information: https://en.wikipedia.org/wiki/Color_difference
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'

引用

Stephen23 (2022). Convert between RGB and Color Names (https://www.mathworks.com/matlabcentral/fileexchange/48155-convert-between-rgb-and-color-names), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2010b
R2009b 以降と互換性あり
プラットフォームの互換性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!