New rainbow colormap: sawthoot-shaped lightness profile

Why another rainbow

In the comment section of my last post Steve Eddins from Mathworks reported that some Matlab users prefer Jet to Parula, the new default perceptual colormap in Matlab, because within certain ranges Jet affords a greater contrast, intended as the rate of change in lightness.

My counter-argument to that is that yes, some data may benefit from being displayed using Jet (in terms of contrast, and hence the power to resolve smaller anomalies) because of those areas of very steep rate of change of lightness, like the blue to cyan and yellow to red portions (see Figure 1). But the price one has to pay is that there is an area of very low gradient (a greenish band between cyan and yellow) where there’s nearly no contrast, which would obfuscate subtle anomalies in the data. On top of that there’s no control of where each of those areas are located, so a lot of effort has to go into trying to fit those regions of artificially high contrast to the portion of data of interest.

L_profile_jet_cl

Figure 1

Because of their high lightness, the yellow and cyan artificial edges also cause problems. In his latest blog post Steve uses a test pattern do demonstrate how they make the interpretation of trivial structures more difficult. He also explains why they occurr in some locations and not others in the first place. I wonder if the resulting regions of high lightness juxtaposed to regions of low lightness could be chromatic Mach bands.

Additionally, as Steve points out, the low-contrast juxtaposition of dark red and dark blue bands creates the visual illusion of depth (Chromostereopsis) in other positions of the test pattern, creating further confusion.

But I have some good news for the hardcore fans of Jet, and rainbow colormaps in general. I created a rainbow with a sawtooth-shaped lightness profile made up of 5 ramps, each with the same  rate of change in lightness and total lightness change of 60, and alternatively negative and positive signs. This is shown in Figure 2, and replaces the lightness profile of a basic 6-color rainbow (magenta-blue-cyan-green-yellow-red) shown in Figure 3.

Figure 2

Figure 2

Figure 2

Figure 3

With this rainbow users have the ability to apply greater contrast to their data to boost small anomalies, but in a more controlled way. The colormap is available with my File Exchange function, Perceptually improved colormaps. Below is the Matlab code I used to generate the new rainbow.

Matlab code

To run this code you will need Colorspace, a free function from Matlab File Exchange, for the color space transformations.

%% basic 6-colour rainbow
% create RGB components
m = [1, 0, 1]; % magenta
b = [0, 0, 1]; % blue
c = [0, 1, 1]; % cyan
g = [0, 1, 0]; % green
y = [1, 1, 0]; % yellow
r = [1, 0, 0]; % red
% concatenate components
rgb = vertcat(m,b,c,g,y,r);
% interpolate to 256 colours
rainbow=interp1(linspace(1, 256, 6),rgb,[1:1:256]);
%% calculate Lab components
% convert from RGB to Lab colour space
% requires this function: Colorspace transforamtions
% www.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations
lab = colorspace('RGB->Lab',rainbow);
%% replace random lightness profile with sawtooth-shaped profile
% contrast (magnitude of lightness change) between
% each pair of adjeacent colors set to 60
L1 = [90, 30, 90, 30, 90, 30];
% interpolate to 256 lightness values
L1int = interp1(linspace(1, 256, 6),L1,[1:1:256])';
% replace
lab1 = horzcat(L1int,lab(:,2),lab(:,3));
%% new rainbow
% convert back from Lab to RGB colour space
swtth = colorspace('RGB<-Lab',lab1);

Test results

Figures 4, 5, and 6 show the three colormaps used with my Pyramid test surface (notice in Figure 5 that the green band artifact with this rainbow is even more pronounced than with jet). I welcome feedback.

Figure 4

Figure 4

Pyramid_basic_rainbow

Figure 5

Figure 4

Figure 6

Aknowledgements

The coloured lightness profiles were made using the Colormapline submission from the Matlab File Exchange.

 

The rainbow is dead…long live the rainbow! – The rainbow is dead…long live the rainbow! – Perceptual palettes, part 2: a rainbow puzzle

ROYGBIV or YOGRVIB?

If you are interested in the topic of color palettes for scientific data, and the rainbow in particular, I would say you ought to read this 2007 IEEE visualization paper by Borland and Taylor: Rainbow Color Map (Still) Considered Harmful. It clearly and elegantly illustrates why the rainbow palette should be avoided when displaying scientific data. I like Figure 1 in the paper in particular. The illustration shows how it is easy to order perceptually a set of 4 paint chips of different gray intensity, but not at all easy to order 4 paint chips colored red, green, yellow, and blue. The author’s argument is that the rainbow colors are certainly ordered, from shorter to longer wavelengths, but they are not perceptually ordered. In this post I wanted to extend the chips example to all 7 colors in the rainbow and try to demonstrate the point in a quantitative way.

Here below is a 256-sample rainbow palette I created interpolating between the RGB values for the seven colors of the rainbow red, orange, yellow, green, blue, indigo, and violet (ROY G BIV):

On this palette I see a number of perceptual artifacts, the most notable ones being a sharp edge at the yellow and a flat zone at the green. The existence of these edges I tried to explain quantitatively in the first post of this series.

Now, to go back to the experiment, from the original RGB values for the non interpolated colors I created the 7 color chips below . Question: can you order them based on their perceived intensity?

I think if you have full color vision (more on the topic of rainbow and impaired color vision in the next section of this post) eventually you will be able to order them as I did.If not, try now below. In this new image I converted the color chips to gray chips using the values obtained in Matlab with this formula:

INT = (0.2989 * RGB(:,1) + 0.5870* RGB(:,2) + 0.1140 * RGB(:,3))';

Give it a try, then hover with your mouse over the image to read the intensity values.

roygbiv_intensityroygbiv_intensity_values

Not surprisingly, the values are not in any particular order. This reinforces the notion that although the rainbow colors are ordered by increasing wavelength (or decreasing in this case) , they are not perceptually ordered. (See this comment to my previous post). Below I rearranged the gray chips by increasing intensity.

And now I reconverted from gray to RGB colors and adjusted the distance between each pair of chips so that it is proportional to the intensity difference between the chips in the pair (I actually had to artificially change the value for green and orange so they would not overlap). That was an epiphany for me. And the name is funny too, BIV R GOY, or YOG R VIB…

I said that it was an epiphany because I realize the implications of trying to create a palette by interpolating through these colors with those distances. So I did it, and I am showing it below in the top color palette. We jumped out of the frying pan, into the fire! We went from perceptual artifacts that are inherent to the rainbow (reproduced in reverse order from blue to red to facilitate comparison as the bottom palette) to interpolation artifacts in the intensity ordered rainbow. Hopeless!

ROYGBIV puzzle

As if what I have shown in the previous section wasn’t scary enough, I took 7 squares and colored them using the same RGB values for Red, Orange, Yellow, Green, Blue, Indigo, and Violet. Then I used the Dichromacy plug-in in ImageJ to simulate how these colors would be seen by a viewer with Deuteranopia (the more common form of color vision deficiency). I then shuffled the squares in random order on a square canvas, and numbered them 1-7 in clockwise order.

Puzzle: can you pair the squares numbered 1 through 7 with the colors R though V? I will give away the obvious one, which is the yellow:

1=Y
2=?
3=?
4=?
5=?
6=?
7=?

Cannot do it? For the solution just hover over the image with your mouse. If you like the animation and would like to use it on your blog, twitter, Facebook, get the GIF file version here. Please be kind enough to link it back to this post.

roygbiv_random_deuteranoperoygbiv_random

Conclusion

When I tried myself I could not solve the puzzle, and that finally convinced me that trying to fix the rainbow was a hopeless cause. Even if we could, it would still confuse a good number of people (about 8% of male have one form or the other of color vision deficiency). From the next post on I will show what I got when I tried to create a better, more perceptual rainbow from scratch.

Related posts (MyCarta)

The rainbow is dead…long live the rainbow! – the full series

What is a colour space? reblogged from Colour Chat

Color Use Guidelines for Mapping and Visualization

A rainbow for everyone

Is Indigo really a colour of the rainbow?

Why is the hue circle circular at all?

A good divergent color palette for Matlab

Related topics (external)

Color in scientific visualization

The dangers of default disdain

Color tools

How to avoid equidistant HSV colors

Non-uniform gradient creator

Colormap tool

Color Oracle – color vision deficiency simulation – stand alone (Window, Mac and Linux)

Dichromacy –  color vision deficiency simulation – open source plugin for ImageJ

Vischeck – color vision deficiency simulation – plugin for ImageJ and Photoshop (Windows and Linux)

For teachers

NASA’s teaching resources for grades 6-9: What’s the Frequency, Roy G. Biv?

What is a colour space?

Since I am deconstructing the rainbow/spectrum in RGB, HSV color spaces, I will show it in dichromat “color space”, and finally will then make a new one in CIE L*a*b* color space I thought I should include a review of the basics. So what is a color space? This good post answers that question.

The rainbow is dead…long live the rainbow! – Perceptual palettes, part 1

Introduction

This is the first  post in a series on the rainbow and similar color palettes. My goal is to demonstrate it is not a good idea to use these palettes to display scientific data, and then answer these two questions: (1) is there anything we can do to “fix” the rainbow, and (2) if not, can we design a new one from scratch.

The rainbow is dead…some examples

In a previous post I showed a pseudo-3D rendering of my left hand x-ray using intensity (which is a measure of bone thickness) as the elevation. I mapped the rendering to both grayscale and rainbow color palettes, and here I reproduced the two images side by side:


I used this example to argue (briefly) that the rainbow obscures some details and confuses images by introducing artifacts. Notice that in this case it clearly reduces the effectiveness of the pseudo-3D rendering in general. It also introduces inversions in the perception of elevation. The thick part in the head of the radius bone, indicated by the arrow, looks like a depression, whereas it is clearly (and correctly) a high in the grayscale version.

Continue reading