next up previous contents
Next: WINLEV Image Window-Level Function Up: Image Display Functions Previous: Image Display Functions   Contents

Subsections

COLORMAP Image Colormap Function

Usage

Changes the colormap used for the display of the indexed (scalar) images in the currently active image window. The generic syntax for its use is

  colormap(map)

where map is a 768 element array (usually organized as 3 \times 256), which defines the RGB (Red Green Blue) coordinates for each color in the colormap.

Function Internals

Assuming that the contents of the colormap function argument c are labeled as:

$\displaystyle c = \begin{bmatrix}
r_1 & g_1 & b_1  \
r_1 & g_2 & b_2  \
r_1 & g_3 & b_3  \
\vdots & \vdots & \vdots
\end{bmatrix}
$

then these columns for the RGB coordinates of pixel in the mapped image. Assume that the image occupies the range $ [a,b]$ . Then the RGB color of each pixel depends on the value $ x$ via the following integer

$\displaystyle k = 1 + \lfloor 256 \frac{x-a}{b-a} \rfloor,
$

so that a pixel corresponding to image value $ x$ will receive RGB color $ [r_k,g_k,b_k]$ . Colormaps are generally used to pseudo color images to enhance visibility of features, etc.

Examples

We start by creating a smoothly varying image of a 2D Gaussian pulse.

--> x = linspace(-1,1,512)'*ones(1,512);
--> y = x';
--> Z = exp(-(x.^2+y.^2)/0.3);
--> image(Z);

which we display with the default (grayscale) colormap here.

8531

Next we switch to the copper colormap, and redisplay the image.

--> colormap(copper);
--> image(Z);

which results in the following image.

8534

If we capture the output of the copper command and plot it, we obtain the following result:

--> a = copper;
--> plot(a);

8537

Note that in the output that each of the color components are linear functions of the index, with the ratio between the red, blue and green components remaining constant as a function of index. The result is an intensity map with a copper tint. We can similarly construct a colormap of our own by defining the three components seperately. For example, suppose we take three gaussian curves, one for each color, centered on different parts of the index space:

--> t = linspace(0,1,256);
--> A = [exp(-(t-1.0).^2/0.1);exp(-(t-0.5).^2/0.1);exp(-t.^2/0.1)]';
--> plot(A);

8540

The resulting image has dark bands in it near the color transitions.

--> image(Z);
--> colormap(A);

8543

These dark bands are a result of the nonuniform color intensity, which we can correct for by renormalizing each color to have the same norm.

--> w = sqrt(sum(A'.^2));
--> sA = diag(1./w)*A;
--> plot(A);

8546

The resulting image has no more dark bands.

--> image(Z);
--> colormap(A);

8549


next up previous contents
Next: WINLEV Image Window-Level Function Up: Image Display Functions Previous: Image Display Functions   Contents
Samit K. Basu 2005-03-16