Code covered by the BSD License  

Highlights from
Perceptually improved colormaps

5.0

5.0 | 9 ratings Rate this file 117 Downloads (last 30 days) File Size: 5.23 MB File ID: #28982
image thumbnail

Perceptually improved colormaps

by

 

08 Oct 2010 (Updated )

6 perceptual colormaps with rainbow-like colors and 1 with heat colors

| Watch this File

File Information
Description

PMKMP Returns perceptually balanced colormaps
   PMKMP(N,SCHEME) returns an Nx3 colormap.
   usage: map=pmkmp(n,scheme);
Example: 128-color rainbow with cubic-law luminance (default)
       % load mandrill;
       % imagesc(X);
       % colormap(pmkmp(128));
       % colorbar;
JUSTIFICATION: rainbow, or spectrum color schemes are considered a poor choice for scientific data display by many in the scientific community (see for example reference 1 and 2 in the help) in that they introduce artefacts that mislead the viewer. "The rainbow color map appears as if it is separated into bands of almost constant hue, with sharp transitions between hues. Viewers perceive these sharp transitions as sharp transitions in the data, even when this is not the casein how regularly spaced (interval) data are displayed (quoted from reference 1). This submission is intended to share the results of my efforts to create more perceptually balanced color maps. Please see output arguments section for descriptions.
See files examples.m, examples1.m, and example2.m and associated figures for more examples
See files MakeLabPlotUsingColorspace.m and CompareLabPlotsUsingColorspace.m for some demonstrations.

See also: JET, HSV, GRAY, HOT, COOL, BONE, COPPER, PINK, FLAG, PRISM, COLORMAP, RGBPLOT
 
Extensive reference list and list of other FEX submissions of interest included in the help

Please visit my blog to read about the background research:
http://mycarta.wordpress.com/2012/05/29/the-rainbow-is-dead-long-live-the-rainbow-series-outline/

Author: Matteo Niccoli
e-mail address: matteo@mycarta.ca
Release: 4.0
Release date: April 2014

Acknowledgements

Spectral And Xyz Color Functions, Shaded Pseudo Color, Cline, Make Color Map, Cold Colormap, and Colorspace Transformations inspired this file.

This file inspired Colormapline Color Changing 2 D Or 3 D Line, Cubehelix Colormaps, and Color Brewer: Attractive And Distinctive Colormaps.

MATLAB release MATLAB 7.5 (R2007b)
MATLAB Search Path
/
/pmkmp
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (24)
16 Jul 2014 Matteo Niccoli

Hi Timothy, thank you for your feedback. And for the suggestion! I just got started with github and am building some tutorials on this in Python (you can check it at github.com/mycarta), but it did not occurr to me to upload the Matlab code as well. Great idea, I'll get to it as soon as I'm done with the Python tutorials.

16 Jul 2014 Timothy

Fantastic colormap! Have you though of placing your code and progress on github as well? That way we can fork, patch, or just update our copies very easily. Thank you again.

06 Jul 2014 Matteo Niccoli

Hi Jakob, thanks for the positive feedback and for pointing that out. I am working on some additional colormaps so when I add those I will also fix the interp1 commands.

06 Jul 2014 Jakob Nikolas

Works fine! An easy to use implementatoin of the color maps explained in the Mycarta blog. One minor issue: running the code I get a compatibility warning ("Warning: INTERP1(...,'CUBIC') will change in a future release. Use INTERP1(...,'PCHIP') instead."). Maybe this should be fixed in the next version.

14 May 2014 Matteo Niccoli

Zack L-B: thanks, I must have loaded an older file accidentally. I just loaded the intended update (2014).

14 May 2014 L. Hare Duncare

The current download appears to be the same as the February 2013 release.

29 Apr 2014 Matteo Niccoli

John: I did not know you could do this:
>> X=(5:-1:-1)
X = 5 4 3 2 1 0 -1
>> X1=max(X,0)
X1 = 5 4 3 2 1 0 0
Wonderful, thanks for the great suggestion, I'll add that.

29 Apr 2014 John D'Errico

Matteo - You could simply catch those spurious negative values from the interpolation using max(x,0) after interp1 has done its work.

29 Apr 2014 Matteo Niccoli

John: thanks for the feedback. You are rigth, the function fails when called as
cmap = pmkmp(1);
The fact in itself that it fails does not worry me too much since these colormaps were intended for data series, so 1 color only would not be meaningful. But it is fair to add an extra check for minimum number of colors, so I added:
if n<2
error('n must be >= 2');
end
If someone wanted to set the display of their data to only one color, there are other ways, e.g.
http://stackoverflow.com/questions/492232/how-do-i-set-a-surf-to-one-color-no-gradient-in-my-matlab-plot
Let me know what you think.

29 Apr 2014 Matteo Niccoli

Joshua: I added the missing switch statements. THanks again.

29 Apr 2014 Matteo Niccoli

Marius: thanks for spotting that. You are rigth, with a call like
colormap(pmkmp(128,'edge'))
you get a very small BUT negative value (-2.220446049250313e-16) for the Red in the last triplet. I think you are also rigth, it is because of interp1, specifically because I selected cubic as the interpolation method.
Since I want to retain that for the other colormaps, I am thinking of creating a separate function for the Edge colormap.

28 Apr 2014 John Mahoney

Hi Matteo,
It looks like pmkmp fails if the number of colors requested is 1.
cmap = pmkmp(1);
Otherwise looks nice!
John

27 Mar 2014 Patrick  
23 Oct 2013 Marius

Very nice idea, never thought about these color perception issues.

There is a small bug in pmkmp.m with my version of MATLAB (8.1.0.604 (R2013a)). When using the edge colormap and n values around 100 (e.g. 128 or 64) I get

>> colormap(pmkmp(128,'edge'))
Error using colormap (line 99)
Colormap must have values in [0,1].

I think this is due to interp1 returning negative values under these circumstances.

29 Aug 2013 Matteo Niccoli

Sebastian, John (and Petros, long overdue) thanks for the positive rating and feedback.

Joshua, thanks for the rating and comments, and also for spotting the error in the code. I just moved back to Canada after a year in Norway and my computer (with Matlab) is on a slow boat, I will re-submit with the corrected code asap.

13 Aug 2013 Sebastian Hölz

Nice,

I just had a long discussion with a colleague a few days ago on "big" anomalies in his plot, which were mainly due to the perception of the chosen colormap (jet).

I really like the "Edge" and "LinearL" colormaps and will must likely start to use them in the future.

10 Aug 2013 John D'Errico

Nice job.

09 Aug 2013 Joshua

Really cool function, never thought about the perceived visual gradients in data due to luminosity mismatch. There was one error in the code where the 'linearl' and 'linlhot' were missing their switch statements. Here is the corrected switch statement on line 295 to access those last two color profiles:

switch lower(scheme)
case 'isol'
baseMap = IsoL;
case 'cubicl'
baseMap = CubicL;
case 'edge'
baseMap = Edge;
case 'cubicyf'
baseMap = CubicYF;
case 'linearl'
baseMap = LinearL
case 'linlhot'
baseMap = LinLhot

otherwise
error(['Invalid scheme ' scheme])
end

28 Feb 2013 Matteo Niccoli

Correct link:
http://mycarta.wordpress.com/2012/05/29/the-rainbow-is-dead-long-live-the-rainbow-series-outline/

30 May 2012 Matteo Niccoli

All research to be published here:
http://mycarta.wordpress.com/2012/05/30/the-rainbow-is-dead-long-live-the-rainbow-series-outline/

23 Apr 2011 Matteo Niccoli

Colin, thank you for your positive comments. I just got back after a trip and saw your post. I will look into improving/clarifying use of examples.m asap. I may wait a bit to implement an updated as I have some add-ons modifications I am working on.

25 Mar 2011 Colin

Really interesting discussion/solution of a topic I hadn't given enough thought to.

Colin

p.s. It might be worth adding:

set(0,'defaultfigureunits','pixels')

to the start of "examples.m". It took me a while to figure out why no figures were visible.

Alternatively you could consider using:

set(fign,'OuterPosition',[0.25 0.25 0.5 0.5],'units','normalized');

25 Mar 2011 Colin  
14 Oct 2010 Petros Mpogiatzis

indeed, perceptually better!

Updates
12 Oct 2010

Added more examples in new file examples1.m
Added one of the reference papers (link disrupted)
Edited H1 line
Added justification paragraph
Modified REFERENCE AND acknowledgements in help
Removed MAC_OS hidden files

13 Oct 2010

Added more examples and demonstrations

22 Oct 2010

flipped isoL colormap so red is on the high intensity side
added one more example
minor edits and typos corrected here and there

20 Aug 2011

updated contact email

23 Mar 2012

Added a 100% perceptual version of cube law rainbow and new examples and references.

28 Mar 2012

Implemented Colin's first suggestion for examples.m

27 Feb 2013

Added a linear lightness rainbow colormap
Added a linear lightness adjusted heat colormap
Added first line to examples.m as suggested by COlin in the comments

29 Apr 2014

Added missing switch statements for 'linearl' and 'linlhot'.
Added error check for minimum number of colors

14 May 2014

On April 29th I loaded by mistake a previous release instead of the new one. This is the correct release.

14 Oct 2014

Replaced INTERP1(...,'CUBIC') with INTERP1(...,'PCHIP') as suggested by Jakob Nikolas in the comments. Added a new isoluminant colormap for cyclical (azimuth or phase).

Contact us