原文:http://blogs.mathworks.com/steve/2006/05/09/a-lab-based-uniform-color-scale/
DSP Tips & Tricks
McNames gives four design principles for selecting an effective color scale (orcolormap, in MATLAB terminology):
- "[The] color scale should cover as much of the range of available colors as possible, subject to the constraint that the luminance increases monotonically (for gray scale publications).
- "Neighboring colors throughout the scale should be as distinct as possible."
- "The perceptual difference between two colors should be approximately proportional to the difference between their positions along the color scale."
- "The color scale should be intuitive."
A path through L*a*b* color space
Let's make a color scale that is a uniform ramp in L*. In the a*-b* plane, trace a semicircular path of radius 50, with angle varying between 0 and pi/2.
radius = 50;
theta = linspace(0, pi/2, 256).';
a = radius * cos(theta);
b = radius * sin(theta);
L = linspace(0, 100, 256).';
Lab = [L, a, b];
Now convert the L*a*b* values to sRGB so we can use it as a MATLAB colormap. Use the Image Processing Toolbox functions
makecform and
applycform.
map = applycform(Lab, makecform('lab2srgb'));
Radon example
Let's use this colormap for looking at a Radon transform image.
I = zeros(100,100);
I(25:75, 25:75) = 1;
theta = 0:180;
[R,xp] = radon(I,theta);
imshow(R,[],'InitialMagnification','fit')
colormap(map)
Color scale function on MATLAB Central
The function color_scale on MATLAB Central lets you easily create color scales like this. You can choose different values for the radius and the starting angle, and you specify a clockwise or counterclockwise path through a*-b* space.
colormap(color_scale)
Color scale GUI
The same MATLAB Central submission contains the color_scale_tool function, which is a GUI that lets you control the color scale parameters with sliders. It also shows you both the color scale and the approximate grayscale equivalent.