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       [-verbose]
23
24       [-debug]
25
26       ncolors|all
27
28       [pnmfile]
29
30

DESCRIPTION

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

PARAMETERS

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

OPTIONS

89       In  addition  to  the options common to all programs based on libnetpbm
90       (most notably -quiet, see
91        Common Options ⟨index.html#commonoptions⟩  ),  pnmcolormap  recognizes
92       the following command line options:
93
94       All  options  can  be abbreviated to their shortest unique prefix.  You
95       may use two hyphens instead of one to designate an option.  You may use
96       either  white  space  or  an equals sign between an option name and its
97       value.
98
99
100
101       -sort  This option causes the output colormap to be sorted by  the  red
102              component  intensity, then the green, then the blue in ascending
103              order.  This is an insertion sort, so it is  not  very  fast  on
104              large  colormaps.   Sorting  is  useful because it allows you to
105              compare two sets of colors.
106
107
108       -square
109              By default, pnmcolormap produces as the color map  a  PPM  image
110              with one row and with one column for each color in the colormap.
111              This option causes pnmcolormap instead to produce  a  PPM  image
112              that  is within one row or column of being square, with the last
113              pixel duplicated as necessary to create a number of pixels which
114              is such an almost-perfect square.
115
116
117       -verbose
118              This  option  causes pnmcolormap to display messages to Standard
119              Error about the quantization..TP -center
120
121
122       -debug This option causes pnmcolormap to display messages  to  Standard
123              Error about internal workings.
124
125
126       -center
127
128
129       -meancolor
130
131
132       -meanpixel
133
134
135       -spreadbrightness
136
137
138       -spreadluminosity
139
140
141       -splitpixelct
142
143
144       -splitcolorct
145
146
147       -splitspread
148              These   options   control   the   quantization  algorithm.   See
149              QUANTIZATION METHOD ⟨#quant⟩ .
150
151
152
153
154

QUANTIZATION METHOD

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

REFERENCES

232       "Color Image Quantization for Frame Buffer Display" by  Paul  Heckbert,
233       SIGGRAPH '82 Proceedings, page 297.
234
235

SEE ALSO

237       pnmremap(1),  pnmquant(1), ppmquantall(1), pamgetcolor(1), pamdepth(1),
238       ppmdither(1), pamseq(1), ppmmake(1), pnmcat(1), ppm(1)
239
240

HISTORY

242       Before Netpbm 10.15 (April 2003), pnmcolormap used a  lot  more  memory
243       for  large  images  because  it  kept the entire input image in memory.
244       Now, it processes it a row at a time, but  because  it  sometimes  must
245       make  multiple passes through the image, it first copies the input into
246       a temporary seekable file if it is not already in a seekable file.
247
248       pnmcolormap first appeared in Netpbm 9.23 (January 2002).  Before that,
249       its  function  was  available  only as part of the function of pnmquant
250       (which was derived from the much older ppmquant).   Color  quantization
251       really  has two main subfunctions, so Netpbm 9.23 split it out into two
252       separate programs: pnmcolormap and pnmremap and then  Netpbm  9.24  re‐
253       placed  pnmquant  with a program that simply calls pnmcolormap and pnm‐
254       remap.
255
256

AUTHOR

258       Copyright (C) 1989, 1991 by Jef Poskanzer.
259

DOCUMENT SOURCE

261       This manual page was generated by the Netpbm tool 'makeman'  from  HTML
262       source.  The master documentation is at
263
264              http://netpbm.sourceforge.net/doc/pnmcolormap.html
265
266netpbm documentation           21 February 2023     Pnmcolormap User Manual(0)
Impressum