File: handle_colormap.html

package info (click to toggle)
freemat 4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 174,756 kB
  • ctags: 67,023
  • sloc: cpp: 351,059; ansic: 255,892; sh: 40,590; makefile: 4,387; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (146 lines) | stat: -rw-r--r-- 3,403 bytes parent folder | download | duplicates (2)
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>
--&gt; x = linspace(-1,1,512)'*ones(1,512);
--&gt; y = x';
--&gt; Z = exp(-(x.^2+y.^2)/0.3);
--&gt; 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>
--&gt; colormap(copper);
--&gt; 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>
--&gt; a = copper;
--&gt; 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>
--&gt; t = linspace(0,1,256);
--&gt; A = [exp(-(t-1.0).^2/0.1);exp(-(t-0.5).^2/0.1);exp(-t.^2/0.1)]';
--&gt; 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>
--&gt; image(Z);
--&gt; 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>
--&gt; w = sqrt(sum(A'.^2));
--&gt; sA = diag(1./w)*A;
--&gt; plot(A);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap6.png">
</DIV>
<P>

The resulting image has no more dark bands.
<PRE>
--&gt; image(Z);
--&gt; colormap(A);
</PRE>
<P>
<P>
<DIV ALIGN="CENTER">
<IMG SRC="colormap7.png">
</DIV>
<P>
</BODY>
</HTML>