File Exchange

image thumbnail

Intuitive RGB color values from XKCD

version 1.5.0.0 (53.8 KB) by Chad Greene
RGB triplets for 949 colors, by how they're perceived on a computer monitor and their common names.

33 Downloads

Updated 12 Jun 2017

View Version History

View License

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.

Cite As

Chad Greene (2020). Intuitive RGB color values from XKCD (https://www.mathworks.com/matlabcentral/fileexchange/46872-intuitive-rgb-color-values-from-xkcd), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (20)

Zhitao GUI

John McDowell

Ngoc-Tram Le

Josh Philipson

Absolutely fantastic. Thank you for sharing.

Aurélia Meister

Natalie Baruch

Chad Greene

Michael: After downloading the file, unzip it and put the contents in your Current Folder, or your Home Folder (called something like ...Users/myname/Documents/MATLAB). Or you can put it in a folder of its own, and from within Matlab, right-click on the folder and say "Add to Path" and choose the option for the folder and subfolders.

Michael McDermott

Hey Chad, where do you install on MATLAB after downloading the file? Do you need to install a separate rgb program? For some reason, MATLAB isn't recognizing the data, even when I save the program as an imported variable...

Chad Greene

Hi Taisiya, Thanks for pointing out this oversight! I'm not sure how that happened. The updated version should work.

Taisiya Dymova

When I download the rgb_v4.zip file, it contains neither xkcd_rgb_data.mat not rgb.txt files...

Kevin

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.

Chad Greene

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.

Florian Klimm

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));

Florian Klimm

Rajesh Rajaram

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

Stephen Cobeldick

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

Stephen Cobeldick

Chad Greene

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

Stephen Cobeldick

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

Stephen Cobeldick

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!

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!

XKCD_RGB/html/