Code covered by the BSD License

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

Highlights from Intuitive RGB color values from XKCD

4.75
4.8 | 6 ratings Rate this file 22 Downloads (last 30 days) File Size: 30.3 KB File ID: #46872 Version: 1.4

Intuitive RGB color values from XKCD

Chad Greene (view profile)

05 Jun 2014 (Updated )

RGB triplets for 949 colors, by how they're perceived on a computer monitor and their common names.

File Information
Description

This function returns the RGB triplet for almost any color. And unlike the way colors are somewhat officially defined (http://en.wikipedia.org/wiki/Web_colors), this data set describes returns values for the ways that colors are actually perceived on computer monitors. Color names are intuitive because they are based on a survey of over 200,000 user sessions, wherein respondents were shown colors and asked to fill in their word for that color. You won't find "puke green" on Wikipedia's list of web colors, despite the fact that it's a color name that people use and understand.
Data come from an XKCD survey described here: http://blog.xkcd.com/2010/05/03/color-survey-results/
A chart of available colors and their most common names can be found here: http://xkcd.com/color/rgb/

Syntax
RGB = rgb('Color Name')
RGB = rgb('Color Name 1','Color Name 2',...,'Color Name N')
RGB = rgb({'Color Name 1','Color Name 2',...,'Color Name N'})

Description
RGB = rgb('Color Name') returns the RGB triplet for a color described by 'Color Name'.

RGB = rgb('Color Name 1','Color Name 2',...,'Color Name N') returns an N by 3 matrix containing RGB triplets for each color name.

RGB = rgb({'Color Name 1','Color Name 2',...,'Color Name N'}) accepts list of color names as a character array.

Acknowledgements
Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
MATLAB Search Path
```/
/XKCD_RGB
/XKCD_RGB/html
/__MACOSX
/__MACOSX/XKCD_RGB```
Tags for This File   Please login to tag files.
 Please login to add a comment or rating.
Comments and Ratings (10)
15 Mar 2016 Kevin

Kevin (view profile)

Great function, I use it all the time. I like the bit that finds near matches if you spell a color wrong. It does a good job so I just edited rgb.m to choose the first-listed nearby name rather than ask me to correct the spelling.

30 Jul 2015 Chad Greene

Chad Greene (view profile)

Thanks for catching this error and tracking down the cause, Florian! I've made the fix you suggest, and I moved the installation script to the rgb function itself.

Comment only
28 Jul 2015 Florian Klimm

Florian Klimm (view profile)

Very good tool.
It might be a problem with Mac or the version of Matlab I am using (R2014b) but I had to change the following lines in the hex2rgb.m since I got an error with the '#' sing not being properly deleted from the string.

%if strcmpi(hex(1,1),'#')
% hex(:,1) = [];
%end
r = hex2dec(hex(:,2:3));
g = hex2dec(hex(:,4:5));
b = hex2dec(hex(:,6:7));

Comment only
28 Jul 2015 Florian Klimm

Florian Klimm (view profile)

12 Feb 2015 Rajesh Rajaram

Rajesh Rajaram (view profile)

Nifty code. One that's sorely needed in Matlab. Thanks for the submission.

08 Aug 2014 Stephen Cobeldick

Stephen Cobeldick (view profile)

PPS: the input checking <iscellstr(ColorNames)==0 && iscellstr({ColorNames})==1> is equivalent to <ischar(ColorNames)> :)

Comment only
08 Aug 2014 Stephen Cobeldick

Stephen Cobeldick (view profile)

08 Aug 2014 Chad Greene

Chad Greene (view profile)

Great catch Stephen, thanks for bringing this to my attention. I neglected to include hex2rgb in yesterday's update. It's now included.

Comment only
08 Aug 2014 Stephen Cobeldick

Stephen Cobeldick (view profile)

PS: although the function "hex2rgb" should either be included, or otherwise clearly indicated that it is required!

24 Jun 2014 Stephen Cobeldick

Stephen Cobeldick (view profile)

This is a very tidy submission. The original XKCD survey makes for a highly entertaining read, and this submission (an import of the survey results into MATLAB) is a great addition by Chad Greene to the MATLAB color handling functions!

Updates
05 Jun 2014 1.1

Link to hex2rgb, rgb2hex.

07 Aug 2014 1.2

Now supports multiple inputs and offers help for misspelled inputs.

08 Aug 2014 1.3

Included hex2rgb function and improved error handling.

30 Jul 2015 1.4

Fixed a bug in the installation script. Installation is now performed fully within the rgb function.

Contact us