pnmcolormap [-center|-meancolor|-meanpixel] [-spreadbrightness|-spread-
luminosity] [-sort] [-square] ncolors|all [pnmfile]
All options can be abbreviated to their shortest unique prefix. You
may use two hyphens instead of one to designate an option. You may use
either white space or an equals sign between an option name and its
Reads a PNM image as input. Chooses ncolors colors to best represent
the image, maps the existing colors to the new ones, and writes a PNM
color map defining them as output.
You can use this map as input to pnmremap on the same input image to
quantize the colors in that image, I.e. produce a similar image with
fewer colors. pnmquant does both the pnmcolormap and pnmremap steps
A PNM colormap is a PNM image of any dimensions that contains at least
one pixel of each color in the set of colors it represents.
The quantization method is Heckbert's "median cut". See the section
If the input image is a PPM, the output image is a PPM. If the input
image is a PBM or PGM, the output colormap is a PGM. Note that a col-
ormap of a PBM image is not very interesting.
The colormap generally has the same maxval as the input image, but pnm-
colormap may reduce it if there are too many colors in the input, as
part of its quantization algorithm.
If you want to create a colormap without basing it on the colors in an
input image, see ppmcolors.
The single parameter, which is required, is the number of colors you
want in the output colormap. pnmcolormap may produce a color map with
slightly fewer colors than that. You may specify all to get a colormap
of every color in the input image (no quantization).
-sort This option causes the output colormap to be sorted by the red
component intensity, then the green, then the blue in ascending
order. This is an insertion sort, so it is not very fast on
large colormaps. Sorting is useful because it allows you to
compare two sets of colors.
These options control the quantization algorithm. See QUANTIZA-
TION METHOD below.
A quantization method is a way to choose which colors, being fewer in
number than in the input, you want in the output. pnmcolormap uses
Heckbert's "median cut" quantization method.
This method involves separating all the colors into "boxes," each hold-
ing colors that represent about the same number of pixels. You start
with one box and split boxes in two until the number of boxes is the
same as the number of colors you want in the output, and choose one
color to represent each box.
When you split a box, you do it so that all the colors in one sub-box
are "greater" than all the colors in the other. "Greater," for a par-
ticular box, means it is brighter in the color component (red, green,
blue) which has the largest spread in that box. pnmcolormap gives you
two ways to define "largest spread.": 1) largest spread of brightness;
2) largest spread of contribution to the luminosity of the color. E.g.
red is weighted much more than blue. Select among these with the
-spreadbrightness and -spreadluminosity options. The default is
pnmcut provides three ways of choosing a color to represent a box: 1)
the center color - the color halfway between the greatest and least
colors in the box, using the above definition of "greater"; 2) the mean
of the colors (each component averaged separately by brightness) in the
box; 3) the mean weighted by the number of pixels of a color in the
Note that in all three methods, there may be colors in the output which
do not appear in the input at all.
Select among these with the -center, -meancolor, and -meanpixel
options. The default is -center.
"Color Image Quantization for Frame Buffer Display" by Paul Heckbert,
12 December 2001 pnmcolormap(1)
Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2018
All Rights Reserved.