1Pnmcolormap User Manual(0)                          Pnmcolormap User Manual(0)
2
3
4

NAME

6       pnmcolormap - create quantization color map for a Netpbm image
7
8

SYNOPSIS

10       pnmcolormap
11
12       [-center|-meancolor|-meanpixel]
13
14       [-spreadbrightness|-spreadluminosity]
15
16       [-splitpixelct|-splitcolorct|-splitspread]
17
18       [-sort]
19
20       [-square]
21
22       ncolors|all
23
24       [pnmfile]
25
26

DESCRIPTION

28       This program is part of Netpbm(1).
29
30       pnmcolormap  reads  a PNM or PAM image as input, chooses ncolors colors
31       to best represent the image and writes a PNM color map defining them as
32       output.   A PAM image may actually contain tuples of any kind, but pnm‐
33       colormap's concept of the tuple values that  best  represent  the  ones
34       present  in the image may not make sense if the tuple type isn't RGB or
35       GRAYSCALE.  The design of the program, and the  rest  of  this  manual,
36       assumes the tuples represent colors.
37
38       You  can  use  this map as input to pnmremap on the same input image to
39       quantize the colors in that image, I.e. produce a  similar  image  with
40       fewer  colors.   pnmquant  does both the pnmcolormap and pnmremap steps
41       for you.
42
43       A PNM colormap is a PNM image of any dimensions that contains at  least
44       one  pixel  of each color in the set of colors it represents.  The ones
45       pnmcolormap generates have exactly one  pixel  of  each  color,  except
46       where padding is necessary with the -square option.
47
48       The  quantization  method is Heckbert's "median cut".  See QUANTIZATION
49       METHOD ⟨#quant⟩ .
50
51       The output image is of the same format (PBM,  PGM,  PPM,  PAM)  as  the
52       input image.  Note that a colormap of a PBM image is not very interest‐
53       ing.
54
55       The colormap generally has the same maxval as the input image, but pnm‐
56       colormap  may  reduce  it if there are too many colors in the input, as
57       part of its quantization algorithm.
58
59       pnmcolormap works on a multi-image input stream.  In that case, it pro‐
60       duces  one  colormap  that  applies  to all of the colors in all of the
61       input images.  All the images must have the  same  format,  depth,  and
62       maxval  (but  may  have different height and width).  This is useful if
63       you need to quantize a bunch of images that will form a movie or other‐
64       wise  be  used together -- you generally want them all to draw from the
65       same palette, whereas computing a colormap separately from  each  image
66       would  make  the  same  color  in  two  images map to different colors.
67       Before Netpbm 10.31 (December  2005),  pnmcolormap  ignored  any  image
68       after the first.
69
70       If  you want to create a colormap without basing it on the colors in an
71       input image, pamseq, ppmmake, and pnmcat can be useful.
72
73

PARAMETERS

75       The single parameter, which is required, is the number  of  colors  you
76       want  in the output colormap.  pnmcolormap may produce a color map with
77       slightly fewer colors than that.  You may specify all to get a colormap
78       of  every color in the input image (no quantization).  When you specify
79       all, the function is essentially the same  as  that  of  ppmhist  -map.
80       ppmhist is much older.
81
82
83

OPTIONS

85       All  options  can  be abbreviated to their shortest unique prefix.  You
86       may use two hyphens instead of one to designate an option.  You may use
87       either  white  space  or  an equals sign between an option name and its
88       value.
89
90
91
92       -sort  This option causes the output colormap to be sorted by  the  red
93              component  intensity, then the green, then the blue in ascending
94              order.  This is an insertion sort, so it is  not  very  fast  on
95              large  colormaps.   Sorting  is  useful because it allows you to
96              compare two sets of colors.
97
98
99       -square
100              By default, pnmcolormap produces as the color map  a  PPM  image
101              with one row and with one column for each color in the colormap.
102              This option causes pnmcolormap instead to produce  a  PPM  image
103              that  is within one row or column of being square, with the last
104              pixel duplicated as necessary to create a number of pixels which
105              is such an almost-perfect square.
106
107
108       -verbose
109              This  option  causes pnmcolormap to display messages to Standard
110              Error about the quantization..TP -center
111
112
113       -meancolor
114
115
116       -meanpixel
117
118
119       -spreadbrightness
120
121
122       -spreadluminosity
123
124
125       -splitpixelct
126
127
128       -splitcolorct
129
130
131       -splitspread
132              These  options  control   the   quantization   algorithm.    See
133              QUANTIZATION METHOD ⟨#quant⟩ .
134
135
136
137
138

QUANTIZATION METHOD

140       A  quantization  method is a way to choose which colors, being fewer in
141       number than in the input, you want in  the  output.   pnmcolormap  uses
142       Heckbert's "median cut" quantization method.
143
144       This method involves separating all the colors into "boxes," each hold‐
145       ing colors that represent about the same number of pixels.   You  start
146       with  one  box  and split boxes in two until the number of boxes is the
147       same as the number of colors you want in the  output,  and  choose  one
148       color to represent each box.
149
150       There are three ways pnmcolormap can choose the box to split in
151         each step:
152
153
154       ·      Split the box containing the most pixels.  This is the default,
155                    and  you  can  select it explicitly with option -splitpix‐
156              elct.
157
158       ·      Split the box containing the most colors.  This  appears  to  be
159              useful
160                    for academic purposes only.  Select this with option
161                    -splitcolorct.
162
163       ·      Split the box containing the largest color spread.  Select this
164                    with  option  -splitspread.   This  can  produce  a better
165              result for
166                    small details with  colors  not  found  elsewhere  in  the
167              image.
168
169
170       -splitpixelct, splitcolorct, and splitspread were new
171         in Netpbm 10.88 (September 2019).  Before that, pnmcolormap always
172         splits the box containing the most pixels.
173
174
175       When  you split a box, you do it so each sub-box has the same number of
176       pixels (except one sub-box has more if the full box has an odd number),
177       with the 'greatest' pixels in one sub-box and the 'least' pixels in the
178       other.  "Greater," for a particular box, means it is  brighter  in  the
179       color component (red, green, blue) which has the largest spread in that
180       box.  pnmcolormap gives you two ways to define  "largest  spread.":  1)
181       largest  spread of brightness; 2) largest spread of contribution to the
182       luminosity of the color.  E.g. red is weighted  much  more  than  blue.
183       Select  among  these  with  the -spreadbrightness and -spreadluminosity
184       options.  The default is -spreadbrightness.  Where there  are  multiple
185       colors  of the median magnitude, they are distributed arbitrarily among
186       between the subboxes.  This arbitrary distribution  depends  upon  what
187       the system's qsort function does with multiple equal values, so pnmcol‐
188       ormap may produce slightly different results on different systems.
189
190       pnmcolormap provides three ways of choosing a color to represent a box:
191       1)  the center color - the color halfway between the greatest and least
192       colors in the box, using the above definition of "greater"; 2) the mean
193       of the colors (each component averaged separately by brightness) in the
194       box; 3) the mean weighted by the number of pixels of  a  color  in  the
195       image.
196
197       Select  among  these  with  the  -center,  -meancolor,  and  -meanpixel
198       options.  The default is -center.
199
200       Note that in all three methods, there may be colors in the output which
201       do not appear in the input at all.
202
203       Also  note  that  the color chosen to represent the colors in Box A the
204       best may also represent a color in Box B better than the  color  chosen
205       to  represent  the  colors in Box B the best.  This is true for various
206       measures of goodness of representation of one  color  by  another.   In
207       particular,  if  you  use  pnmremap to map the colors in the very image
208       that you used to create the color map to the colors in  that  colormap,
209       the  colors  in  Box B will often map to the color pnmcolormap chose to
210       represent some other box and in fact the  color  pnmcolormap  chose  to
211       represent Box B may not appear in the pnmremap output at all.
212
213
214

REFERENCES

216       "Color  Image  Quantization for Frame Buffer Display" by Paul Heckbert,
217       SIGGRAPH '82 Proceedings, page 297.
218
219

SEE ALSO

221       pnmremap(1), pnmquant(1), ppmquantall(1), pamgetcolor(1),  pamdepth(1),
222       ppmdither(1), pamseq(1), ppmmake(1), pnmcat(1), ppm(1)
223
224

HISTORY

226       Before  Netpbm  10.15  (April 2003), pnmcolormap used a lot more memory
227       for large images because it kept the  entire  input  image  in  memory.
228       Now,  it  processes  it  a row at a time, but because it sometimes must
229       make multiple passes through the image, it first copies the input  into
230       a temporary seekable file if it is not already in a seekable file.
231
232       pnmcolormap first appeared in Netpbm 9.23 (January 2002).  Before that,
233       its function was available only as part of  the  function  of  pnmquant
234       (which  was  derived from the much older ppmquant).  Color quantization
235       really has two main subfunctions, so Netpbm 9.23 split it out into  two
236       separate  programs:  pnmcolormap  and  pnmremap  and  then  Netpbm 9.24
237       replaced pnmquant with a program that simply calls pnmcolormap and pnm‐
238       remap.
239
240

AUTHOR

242       Copyright (C) 1989, 1991 by Jef Poskanzer.
243

DOCUMENT SOURCE

245       This  manual  page was generated by the Netpbm tool 'makeman' from HTML
246       source.  The master documentation is at
247
248              http://netpbm.sourceforge.net/doc/pnmcolormap.html
249
250netpbm documentation           09 February 2019     Pnmcolormap User Manual(0)
Impressum