1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>COLORMAP Image Colormap Function
</TITLE>
</HEAD>
<BODY>
<H2>COLORMAP Image Colormap Function
</H2>
<P>
Section: <A HREF=sec_handle.html> Handle-Based Graphics </A>
<H3>Usage</H3>
Changes the colormap for the current figure. The generic syntax
for its use is
<PRE>
colormap(map)
</PRE>
<P>
where <code>map</code> is a an array organized as <code>3 \times N</code>),
which defines the RGB (Red Green Blue) coordinates for each color in the
colormap. You can also use the function with no arguments to recover
the current colormap
<PRE>
map = colormap
</PRE>
<P>
<H3>Function Internals</H3>
Assuming that the contents of the colormap function argument <code>c</code> are
labeled as:
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap_eqn1.png">
</DIV>
<P>
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
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap_eqn2.png">
</DIV>
<P>
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.
<H3>Examples</H3>
We start by creating a smoothly varying image of a 2D Gaussian pulse.
<PRE>
--> x = linspace(-1,1,512)'*ones(1,512);
--> y = x';
--> Z = exp(-(x.^2+y.^2)/0.3);
--> image(Z);
</PRE>
<P>
which we display with the default (grayscale) colormap here.
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap1.png">
</DIV>
<P>
Next we switch to the <code>copper</code> colormap, and redisplay the image.
<PRE>
--> colormap(copper);
--> image(Z);
</PRE>
<P>
which results in the following image.
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap2.png">
</DIV>
<P>
If we capture the output of the <code>copper</code> command and plot it, we obtain
the following result:
<PRE>
--> a = copper;
--> plot(a);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap3.png">
</DIV>
<P>
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:
<PRE>
--> 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);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap4.png">
</DIV>
<P>
The resulting image has dark bands in it near the color transitions.
<PRE>
--> image(Z);
--> colormap(A);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap5.png">
</DIV>
<P>
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.
<PRE>
--> w = sqrt(sum(A'.^2));
--> sA = diag(1./w)*A;
--> plot(A);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap6.png">
</DIV>
<P>
The resulting image has no more dark bands.
<PRE>
--> image(Z);
--> colormap(A);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap7.png">
</DIV>
<P>
</BODY>
</HTML>
|