Debian Codegraph @

userguide/pnmcolormap.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
2 <html><head><title>Pnmcolormap User Manual</title></head>
3 <body>
4 <h1>pnmcolormap</h1>
5 Updated: 21 February 2023
6 <br>
7 <a href="#index">Table Of Contents</a>
8
9 <h2>NAME</h2>
10
11 pnmcolormap - create quantization color map for a Netpbm image
12
13 <h2 id="synopsis">SYNOPSIS</h2>
14
15 <b>pnmcolormap</b>
16
17 [<b>-center</b>|<b>-meancolor</b>|<b>-meanpixel</b>]
18
19 [<b>-spreadbrightness</b>|<b>-spreadluminosity</b>]
20
21 [<b>-splitpixelct</b>|<b>-splitcolorct</b>|<b>-splitspread</b>]
22
23 [<b>-sort</b>]
24
25 [<b>-square</b>]
26
27 [<b>-verbose</b>]
28
29 [<b>-debug</b>]
30
31 <i>ncolors</i>|<b>all</b>
32
33 [<i>pnmfile</i>]
34
35 <h2 id="description">DESCRIPTION</h2>
36
37 <p>This program is part of <a href="index.html">Netpbm</a>.
38
39 <p><b>pnmcolormap</b> reads a PNM or PAM image as input, chooses
40 <i>ncolors</i> colors to best represent the image and writes a PNM
41 color map defining them as output. A PAM image may actually contain
42 tuples of any kind, but <b>pnmcolormap</b>'s concept of the tuple values
43 that best represent the ones present in the image may not make sense if
44 the tuple type isn't RGB or GRAYSCALE. The design of the program, and
45 the rest of this manual, assumes the tuples represent colors.
46
47 <p>You can use this map as input to <b>pnmremap</b> on the same input
48 image to quantize the colors in that image, I.e. produce a similar
49 image with fewer colors. <b>pnmquant</b> does both the <b>pnmcolormap</b>
50 and <b>pnmremap</b> steps for you.
51
52 <p>A PNM colormap is a PNM image of any dimensions that contains at
53 least one pixel of each color in the set of colors it represents. The
54 ones <b>pnmcolormap</b> generates have exactly one pixel of each color,
55 except where padding is necessary with the <b>-square</b> option.
56
57 <p>The quantization method is Heckbert's "median cut".
58 See <a href="#quant">QUANTIZATION METHOD</a>.
59
60 <p>The output image is of the same format (PBM, PGM, PPM, PAM) as the
61 input image. Note that a colormap of a PBM image is not very
62 interesting.
63
64 <p>The colormap generally has the same maxval as the input image, but
65 <b>pnmcolormap</b> may reduce it if there are too many colors in the
66 input, as part of its quantization algorithm.
67
68 <p><b>pnmcolormap</b> works on a multi-image input stream. In that
69 case, it produces one colormap that applies to all of the colors in
70 all of the input images. All the images must have the same format,
71 depth, and maxval (but may have different height and width). This is
72 useful if you need to quantize a bunch of images that will form a
73 movie or otherwise be used together -- you generally want them all to
74 draw from the same palette, whereas computing a colormap separately
75 from each image would make the same color in two images map to
76 different colors. Before Netpbm 10.31 (December 2005), <b>pnmcolormap</b>
77 ignored any image after the first.
78
79 <p>If you want to create a colormap without basing it on the colors in
80 an input image, <b>pamseq</b>, <b>ppmmake</b>, and <b>pamcat</b> can
81 be useful.
82
83 <h2 id="parameters">PARAMETERS</h2>
84
85 <p>The single parameter, which is required, is the number of colors you want
86 in the output colormap. <b>pnmcolormap</b> may produce a color map with
87 slightly fewer colors than that. You may specify <b>all</b> to get a colormap
88 of every color in the input image (no quantization). When you specify
89 <b>all</b>, the function is essentially the same as that of <b>ppmhist
90 -map</b>. <b>ppmhist</b> is much older.
91
92
93 <h2 id="options">OPTIONS</h2>
94
95 <p>In addition to the options common to all programs based on libnetpbm
96 (most notably <b>-quiet</b>, see <a href="index.html#commonoptions">
97 Common Options</a>), <b>pnmcolormap</b> recognizes the following
98 command line options:
99
100 <p>All options can be abbreviated to their shortest unique prefix. You
101 may use two hyphens instead of one to designate an option. You may
102 use either white space or an equals sign between an option name and
103 its value.
104
105 <dl compact>
106 <dt><b>-sort</b>
107
108 <dd>This option causes the output colormap to be sorted by the red
109 component intensity, then the green, then the blue in ascending order.
110 This is an insertion sort, so it is not very fast on large colormaps.
111 Sorting is useful because it allows you to compare two sets of colors.
112
113 <dt><b>-square</b>
114
115 <dd>By default, <b>pnmcolormap</b> produces as the color map a PPM
116 image with one row and with one column for each color in the colormap.
117 This option causes <b>pnmcolormap</b> instead to produce a PPM image
118 that is within one row or column of being square, with the last pixel
119 duplicated as necessary to create a number of pixels which is such an
120 almost-perfect square.
121
122 <dt><b>-verbose</b>
123
124 <dd>This option causes <b>pnmcolormap</b> to display messages to
125 Standard Error about the quantization. <dt><b>-center</b>
126
127 <dt><b>-debug</b>
128
129 <dd>This option causes <b>pnmcolormap</b> to display messages to
130 Standard Error about internal workings.
131
132 <dt><b>-center</b>
133
134 <dt><b>-meancolor</b>
135
136 <dt><b>-meanpixel</b>
137
138 <dt><b>-spreadbrightness</b>
139
140 <dt><b>-spreadluminosity</b>
141
142 <dt><b>-splitpixelct</b>
143
144 <dt><b>-splitcolorct</b>
145
146 <dt><b>-splitspread</b>
147
148 <dd>These options control the quantization algorithm. See <a
149 href="#quant">QUANTIZATION METHOD</a>.
150
151 </dl>
152
153
154 <h2 id="quant">QUANTIZATION METHOD</h2>
155
156 <p>A quantization method is a way to choose which colors, being fewer
157 in number than in the input, you want in the output.
158 <b>pnmcolormap</b> uses Heckbert's "median cut" quantization
159 method.
160
161 <p>This method involves separating all the colors into
162 "boxes," each holding colors that represent about the same
163 number of pixels. You start with one box and split boxes in two until
164 the number of boxes is the same as the number of colors you want in
165 the output, and choose one color to represent each box.
166
167 <p>There are three ways <b>pnmcolormap</b> can choose the box to split in
168 each step:
169 <ul>
170 <li>Split the box containing the most pixels. This is the default,
171 and you can select it explicitly with option <b>-splitpixelct</b>.
172 <li>Split the box containing the most colors. This appears to be useful
173 for academic purposes only. Select this with option
174 <b>-splitcolorct</b>.
175 <li>Split the box containing the largest color spread. Select this
176 with option <b>-splitspread</b>. This can produce a better result for
177 small details with colors not found elsewhere in the image.
178 </ul>
179
180 <p><b>-splitpixelct</b>, <b>splitcolorct</b>, and <b>splitspread</b> were new
181 in Netpbm 10.88 (September 2019). Before that, <b>pnmcolormap</b> always
182 splits the box containing the most pixels.
183
184 <p>When you split a box, you do it so each sub-box has the same number of
185 pixels (except one sub-box has more if the full box has an odd number), with
186 the &quot;greatest&quot; pixels in one sub-box and the &quot;least&quot;
187 pixels in the other. "Greater," for a particular box, means it is brighter in
188 the color component (red, green, blue) which has the largest spread in that
189 box. <b>pnmcolormap</b> gives you two ways to define "largest spread.": 1)
190 largest spread of brightness; 2) largest spread of contribution to the
191 luminosity of the color. E.g. red is weighted much more than blue. Select
192 among these with the <b>-spreadbrightness</b> and <b>-spreadluminosity</b>
193 options. The default is <b>-spreadbrightness</b>. Where there are multiple
194 colors of the median magnitude, they are distributed arbitrarily among between
195 the subboxes.
196
197 This arbitrary distribution is repeatable, though, for a given Netpbm version
198 -- every invocation of <b>pnmcolormap</b> generates the same color map.
199 Before Netpbm 11.03 (June 2023), the distribution would depend upon what the
200 system's <b>qsort</b> function does with multiple equal values, so
201 <b>pnmcolormap</b> may produce slightly different results on different
202 systems.
203
204 <p><b>pnmcolormap</b> provides three ways of choosing a color to represent a
205 box: 1) the center color - the color halfway between the greatest and least
206 colors in the box, using the above definition of "greater"; 2) the mean of the
207 colors (each component averaged separately by brightness) in the box; 3) the
208 mean weighted by the number of pixels of a color in the image.
209
210 <p>Select among these with the <b>-center</b>, <b>-meancolor</b>, and
211 <b>-meanpixel</b> options. The default is <b>-center</b>.
212
213 <p>Note that in all three methods, there may be colors in the output
214 which do not appear in the input at all.
215
216 <p>Also note that the color chosen to represent the colors in Box A the best
217 may also represent a color in Box B better than the color chosen to represent
218 the colors in Box B the best. This is true for various measures of goodness
219 of representation of one color by another. In particular, if you
220 use <b>pnmremap</b> to map the colors in the very image that you used to
221 create the color map to the colors in that colormap, the colors in Box B will
222 often map to the color <b>pnmcolormap</b> chose to represent some other box
223 and in fact the color <b>pnmcolormap</b> chose to represent Box B may not
224 appear in the <b>pnmremap</b> output at all.
225
226
227 <h2 id="references">REFERENCES</h2>
228
229 "Color Image Quantization for Frame Buffer Display" by Paul Heckbert,
230 SIGGRAPH '82 Proceedings, page 297.
231
232 <h2 id="seealso">SEE ALSO</h2>
233
234 <b><a href="pnmremap.html">pnmremap</a></b>,
235 <b><a href="pnmquant.html">pnmquant</a></b>,
236 <b><a href="ppmquantall.html">ppmquantall</a></b>,
237 <b><a href="pamgetcolor.html">pamgetcolor</a></b>,
238 <b><a href="pamdepth.html">pamdepth</a></b>,
239 <b><a href="ppmdither.html">ppmdither</a></b>,
240 <b><a href="pamseq.html">pamseq</a></b>,
241 <b><a href="ppmmake.html">ppmmake</a></b>,
242 <b><a href="pamcat.html">pamcat</a></b>,
243 <b><a href="ppm.html">ppm</a></b>
244
245 <h2 id="history">HISTORY</h2>
246
247 <p>Before Netpbm 10.15 (April 2003), <b>pnmcolormap</b> used a lot
248 more memory for large images because it kept the entire input image in
249 memory. Now, it processes it a row at a time, but because it
250 sometimes must make multiple passes through the image, it first copies
251 the input into a temporary seekable file if it is not already in a seekable
252 file.
253
254 <p><b>pnmcolormap</b> first appeared in Netpbm 9.23 (January 2002).
255 Before that, its function was available only as part of the function
256 of <b>pnmquant</b> (which was derived from the much older
257 <b>ppmquant</b>). Color quantization really has two main subfunctions, so
258 Netpbm 9.23 split it out into two separate programs:
259 <b>pnmcolormap</b> and <b>pnmremap</b> and then Netpbm 9.24 replaced
260 <b>pnmquant</b> with a program that simply calls <b>pnmcolormap</b> and
261 <b>pnmremap</b>.
262
263 <h2 id="author">AUTHOR</h2>
264
265 Copyright (C) 1989, 1991 by Jef Poskanzer.
266
267
268 <hr>
269 <h2 id="index">Table Of Contents</h2>
270 <ul>
271 <li><a href="#synopsis">SYNOPSIS</a>
272 <li><a href="#description">DESCRIPTION</a>
273 <li><a href="#parameters">PARAMETERS</a>
274 <li><a href="#options">OPTIONS</a>
275 <li><a href="#quant">QUANTIZATION METHOD</a>
276 <li><a href="#references">REFERENCES</a>
277 <li><a href="#seealso">SEE ALSO</a>
278 <li><a href="#history">HISTORY</a>
279 <li><a href="#author">AUTHOR</a>
280 </ul>
281 </body>
282 </html>