File: node130.html

package info (click to toggle)
gmt-doc 3.4-1.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,756 kB
  • ctags: 1,800
  • sloc: makefile: 30
file content (398 lines) | stat: -rw-r--r-- 17,101 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<!--Converted with LaTeX2HTML 99.2beta8 (1.46)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>I. Color Space -- The final frontier</TITLE>
<META NAME="description" CONTENT="I. Color Space -- The final frontier">
<META NAME="keywords" CONTENT="GMT_Docs">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v99.2beta8">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

<LINK REL="STYLESHEET" HREF="GMT_Docs.css">

<LINK REL="next" HREF="node131.html">
<LINK REL="previous" HREF="node125.html">
<LINK REL="up" HREF="GMT_Docs.html">
<LINK REL="next" HREF="node131.html">
</HEAD>

<BODY  bgcolor="#ffffff">
<!--Navigation Panel-->
<A NAME="tex2html2872"
  HREF="node131.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.gif"></A> 
<A NAME="tex2html2866"
  HREF="GMT_Docs.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.gif"></A> 
<A NAME="tex2html2860"
  HREF="node129.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.gif"></A> 
<A NAME="tex2html2868"
  HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.gif"></A> 
<A NAME="tex2html2870"
  HREF="node149.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.gif"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2873"
  HREF="node131.html">J. Filtering of data</A>
<B> Up:</B> <A NAME="tex2html2867"
  HREF="GMT_Docs.html">The Generic Mapping Tools</A>
<B> Previous:</B> <A NAME="tex2html2861"
  HREF="node129.html">H.4 Hints</A>
 &nbsp <B>  <A NAME="tex2html2869"
  HREF="node1.html">Contents</A></B> 
 &nbsp <B>  <A NAME="tex2html2871"
  HREF="node149.html">Index</A></B> 
<BR>
<BR>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION002400000000000000000"></A>
<A NAME="15075"></A>
<BR>
I. Color Space -- The final frontier
</H1>

<P>
Beginning with <A NAME="tex2html681"
  HREF="http://www.soest.hawaii.edu/gmt"><B>GMT</B></A> version 2.1.4, ``Example 11'' was included in
the cookbook.  The example makes an RGB color cube by a simple
<I>awk</I><A NAME="15157"></A> script.  We wrote a program to compute HSV grids for
each face of this cube, and include a version of the cube with
HSV contours on it as file <U>contoured_cube.ps</U> in /share.

<P>
<A NAME="15079"></A>
<A NAME="15080"></A>
<A NAME="15081"></A>
<A NAME="15082"></A>

<P>
In this appendix, we are going to try to explain the relationship
between the RGB and HSV color systems so as to (hopefully) make
them more intuitive.  <A NAME="tex2html682"
  HREF="http://www.soest.hawaii.edu/gmt"><B>GMT</B></A> allows users to specify colors in cpt
files in either system (colors on command lines, such as pen colors
in <B>-W</B> option, are always in RGB).  <A NAME="tex2html683"
  HREF="http://www.soest.hawaii.edu/gmt"><B>GMT</B></A> uses the HSV system to
achieve artificial illumination of colored images (e.g. <B>-I</B>
option in <A NAME="tex2html684"
  HREF="../grdimage.html"><I><B>grdimage</B></I></A><A NAME="15172"></A>) by changing the <I>s</I> and <I>v</I>
coordinates of the color.  When the intensity is zero, the data
are colored according to the cpt file.  If the intensity is
non-zero, the data are given a starting color from the cptfile
but this color (after conversion to HSV if necessary) is then
changed by moving (<I>s,</I><I>v</I>) toward HSV_MIN_SATURATION,
HSV_MIN_VALUE if the intensity is negative, or toward
HSV_MAX_SATURATION, HSV_MAX_VALUE if positive.  These are
defined in the <U>.gmtdefaults</U> file and are usually
chosen so the corresponding points are nearly black (<I>s</I> = 1,
<I>v</I> = 0) and white (<I>s</I> = 0, <I>v</I> = 1).
The reason this works is that the HSV system allows movements in
color space which correspond more closely to what we mean by
``tint'' and ``shade''; an instruction like ``add white'' is
easy in HSV and not so obvious in RGB.

<P>
We are going to try to give you a geometric picture of color
mixing in HSV from a tour of the RGB cube.  The geometric
picture is helpful, we think, since HSV are not orthogonal
coordinates and not found from RGB by an algebraic transformation.
But before we begin traveling on the RGB cube, let us give two
formulae, since an equation is often worth a thousand words. 
<BR>
<P>
<!-- MATH
 $\begin{array}{ccl} 
\par v &	=	&	max (r, g, b)	\\
s &	=	&	(max (r, g, b) - min (r, g, b)) / max (r, g, b)
\end{array}$
 -->
<IMG
 WIDTH="321" HEIGHT="54" ALIGN="MIDDLE" BORDER="0"
 SRC="img175.gif"
 ALT="\( \begin{array}{ccl}
\par v &amp; = &amp; max (r, g, b) \\
s &amp; = &amp; (max (r, g, b) - min (r, g, b)) / max (r, g, b)
\end{array} \)"> 
<BR>
<P>
Note that when <IMG
 WIDTH="93" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img171.gif"
 ALT="$r=g=b=0$"> (black), the expression for <I>s</I>
gives 0/0; black is a singular point for <I>s</I>.  The expression
for <I>h</I> is not easily given without lots of ``if'' tests, but
has a simple geometric explanation.  So here goes: Look at the
cube face with black, red, magenta, and blue corners.
This is the <I>g</I> = 0 face.  Orient the cube so that you are
looking at this face with black in the lower left corner.  Now
imagine a right-handed cartesian <I>(r, g, b)</I> coordinate system
with origin at the black point; you are looking at the <IMG
 WIDTH="39" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img176.gif"
 ALT="$g = 0$">
plane with <I>r</I> increasing to your right, <I>g</I> increasing
away from you, and <I>b</I> increasing up.  Keep this sense of
<I>(r, g, b)</I> as you look at the cube.

<P>
The RGB color cube has six faces.  On three of these one of
<I>(r, g, b)</I> is equal to 0.  These three faces meet at the
black corner, where <IMG
 WIDTH="93" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img171.gif"
 ALT="$r=g=b=0$">.  On these three faces
saturation, the S in HSV, has its maximum value; <I>s</I> = 1
on these faces.  (Accept this definition and ignore the <I>s</I>
singularity at black for now).  Therefore <I>h</I> and <I>v</I> are
contoured on these faces; <I>h</I> in gray solid lines and <I>v</I>
in white dashed lines (<I>v</I> ranges from 0 to 1 and is contoured
in steps of 0.1).

<P>
On the other three faces one of <I>(r, g, b)</I> is equal to the
maximum value.  These three faces meet at the white corner, where
<!-- MATH
 $r = g = b = 255$
 -->
<IMG
 WIDTH="109" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img177.gif"
 ALT="$r = g = b = 255$">.  On these three faces value, the V in HSV, has
its maximum value; <I>v</I> = 1 on these faces.  Therefore <I>h</I>
and <I>s</I> are contoured on these faces; <I>h</I> in gray solid
lines and <I>s</I> in black dashed lines (<I>s</I> ranges from 0 to
1 with contours every 0.1).

<P>
The three faces where <I>v</I> = 1 meet the three faces where <IMG
 WIDTH="38" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img178.gif"
 ALT="$s = 1$">
in six edges where both <IMG
 WIDTH="64" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img179.gif"
 ALT="$s = v = 1$"> (and at least one of <I>(r, g, b)</I>
= 0 and at least one of <I>(r, g, b)</I> = 255).  Trace your finger
around these edges, starting at the red point and moving to the yellow
point, then on around.  You will visit six of the eight corners of the
cube, in this order:  red (<IMG
 WIDTH="39" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img180.gif"
 ALT="$h = 0$">); yellow (<IMG
 WIDTH="47" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img181.gif"
 ALT="$h = 60$">); green
(<IMG
 WIDTH="55" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img182.gif"
 ALT="$h = 120$">); cyan (<IMG
 WIDTH="55" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img183.gif"
 ALT="$h = 180$">); blue (<IMG
 WIDTH="55" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img184.gif"
 ALT="$h = 240$">); magenta
(<IMG
 WIDTH="55" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img185.gif"
 ALT="$h = 300$">).  Three of these are the RGB colors; the other three
are the CMY colors which are the complement of RGB and are used in many
color hardcopy devices (color monitors usually use RGB).  The only cube
corners you did not visit on this path are the black and white corners.
Imagine an axis running through the black and white corners.  If you
project the RYGCBM edge path onto a plane perpendicular to the black-white
axis, the path will look like a hexagon, with RYGCBM at the vertices,
every 60<IMG
 WIDTH="11" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="img61.gif"
 ALT="$^{o}$"> apart.  Now we can make a geometric definition of hue:
Take a vector from the origin (black point) to any point in the cube;
project this vector onto the plane with the RYGCBM hexagon; then hue is
the angle this projected vector makes with the R direction on the hexagon.
Thus hue is an angle describing rotation around the black-white axis.
Note that by this definition, if a point is on the black-white axis, its
<I>(r, g, b)</I> vector will project as a point at the center of the
hexagon, so its hue is undefined.  Points on the black-white axis have
<IMG
 WIDTH="65" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img170.gif"
 ALT="$r=g=b$">, and they are shades of gray; we will call the black-white
axis the gray axis.

<P>
Let us call the points where <IMG
 WIDTH="64" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img179.gif"
 ALT="$s = v = 1$"> (the points on the RYGCBM
path of cube edges) the ``pure'' colors.  If we start at a pure color
and we want to whiten it, we can keep <I>h</I> constant and <IMG
 WIDTH="39" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img186.gif"
 ALT="$v = 1$">
while decreasing <I>s</I>; this will move us along one of the cube
faces toward the white point.  If we start at a pure color and we want
to blacken it, we can keep <I>h</I> constant and <IMG
 WIDTH="38" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img178.gif"
 ALT="$s = 1$"> while decreasing
<I>v</I>; this will move us along one of the cube faces toward the black
point.  Any point in <I>(r, g, b)</I> space which can be thought of as a
mixture of pure color + white, or pure color + black, is on a face of
the cube.

<P>
The points in the interior of the cube are a little harder to describe.
The definition for <I>h</I> above works at all points in (non-gray)
<I>(r, g, b)</I> space, but so far we have only looked at (<I>s</I>,
<I>v</I>) on the cube faces, not inside it.  At interior points, none
of <I>(r, g, b)</I> is equal to either 0 or 255.  Choose such a point,
not on the gray axis.  Now draw a line through your point so that the
line intersects the gray axis and also intersects the RYGCBM path of
edges somewhere.  It is always possible to construct this line, and
all points on this line have the same hue.  This construction shows
that any point in RGB space can be thought of as a mixture of a pure
color plus a shade of gray.  If we move along this line away from the
gray axis toward the pure color, we are ``purifying'' the color by
``removing gray''; this move increases the color's saturation.  When
we get to the point where we cannot remove any more gray, at least one
of <I>(r, g, b)</I> will have become zero and the color is now fully
saturated; <IMG
 WIDTH="38" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img178.gif"
 ALT="$s = 1$">.  Conversely, any point on the gray axis is
completely undersaturated, so that <IMG
 WIDTH="38" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img187.gif"
 ALT="$s = 0$"> there.  Now we see that
the black point is special, because it is the intersection of three
planes on which <IMG
 WIDTH="38" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img178.gif"
 ALT="$s = 1$">, but it is on a line where <IMG
 WIDTH="38" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img187.gif"
 ALT="$s = 0$">; it is a
singular point, and we get ``0/0'' in the above formula.  We see also
that saturation is a measure of ``purity'' or ``vividness'' of the
color.

<P>
It remains to define value, and the formula above is really the best
definition.  But if you like our geometric constructions, try this:
Take your point in RGB space and construct a line through it so that
this line goes through the black point; produce this line from black
past your point until it hits a face on which <IMG
 WIDTH="39" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img186.gif"
 ALT="$v = 1$">.  All points
on this line have the same hue.  Note that this line and the line we
made in the previous paragraph are both contained in the plane whose
equation is hue = constant.  These two lines meet at some arbitrary
angle which varies depending on which point you chose.  Thus HSV is
not an orthogonal coordinate system.  If the line you made in the
previous paragraph happened to touch the gray axis at the black point,
then these two lines are the same line, which is why the black point
is special.  Now, the line we made in this paragraph illustrates the
following:  If your chosen point is not already at the end of the
line, where <IMG
 WIDTH="39" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="img186.gif"
 ALT="$v = 1$">, then it is possible to move along the line in
that direction so as to increase <I>(r, g, b)</I> while keeping the
same hue.  The effect this has on a color monitor is to make the
color shine more brightly, but ``brightness'' has other meanings in
color geometry, so let us say that if you can move in this way, you
can make your hue ``stronger''; if you are already on a plane where
at least one of <I>(r, g, b)</I> = 255, then you cannot get a stronger
version of the same hue.  Thus, <I>v</I> measures strength.  Note that
it is not quite true to say that <I>v</I> measures distance away from
the black point, because <I>v</I> is not equal to <!-- MATH
 $\sqrt{r^2 + g^2 + b^2}/255$
 -->
<IMG
 WIDTH="128" HEIGHT="38" ALIGN="MIDDLE" BORDER="0"
 SRC="img188.gif"
 ALT="$\sqrt{r^2 + g^2 + b^2}/255$">.

<P>
The RGB system is understandable because it is cartesian, and we all
learned cartesian coordinates in school.  But it doesn't help us
create a tint or shade of a color; we cannot say, ``We want orange,
and a lighter shade of orange, or a less vivid orange''.  With HSV we
can do this, by saying, ``Orange must be between red and yellow, so
its hue is about <I>h</I> = 30; a less vivid orange has a lesser
<I>s</I>, a darker orange has a lesser <I>v</I>''.  On the other hand,
the HSV system is a peculiar geometric construction, it is not an
orthogonal coordinate system, and it is not found by a matrix
transformation of RGB; these make it difficult in some cases too.
Note that a move toward black or a move toward white will change both
<I>s</I> and <I>v</I>, in the general case of an interior point in the
cube. The HSV system also doesn't behave well for very dark colors,
where the gray point is near black and the two lines we constructed
above are almost parallel.  If you are trying to create nice colors
for drawing chocolates, for example, you may be better off guessing
in RGB coordinates.

<P>
Well, there you have it, folks.  We've been doing <A NAME="tex2html685"
  HREF="http://www.soest.hawaii.edu/gmt"><B>GMT</B></A> for 10 years
and all we know about color can be written in about 2 pages.  We
hope we haven't told you any lies.  For more details, you should
consult a book about color systems.  But as example 11 shows, a lot
can be learned by experimenting with <A NAME="tex2html686"
  HREF="http://www.soest.hawaii.edu/gmt"><B>GMT</B></A> tools.  Our thanks to John
Lillibridge for Example 11.

<P>
<A NAME="15148"></A>
<A NAME="15149"></A>
<A NAME="15150"></A>
<A NAME="15151"></A>
<A NAME="15152"></A>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html2872"
  HREF="node131.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.gif"></A> 
<A NAME="tex2html2866"
  HREF="GMT_Docs.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.gif"></A> 
<A NAME="tex2html2860"
  HREF="node129.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.gif"></A> 
<A NAME="tex2html2868"
  HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.gif"></A> 
<A NAME="tex2html2870"
  HREF="node149.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.gif"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html2873"
  HREF="node131.html">J. Filtering of data</A>
<B> Up:</B> <A NAME="tex2html2867"
  HREF="GMT_Docs.html">The Generic Mapping Tools</A>
<B> Previous:</B> <A NAME="tex2html2861"
  HREF="node129.html">H.4 Hints</A>
 &nbsp <B>  <A NAME="tex2html2869"
  HREF="node1.html">Contents</A></B> 
 &nbsp <B>  <A NAME="tex2html2871"
  HREF="node149.html">Index</A></B> 
<!--End of Navigation Panel-->
<ADDRESS>
Paul Wessel
2001-04-18
</ADDRESS>
</BODY>
</HTML>