Plan 9 from Bell Labs’s /usr/web/sources/contrib/pac/sys/doc/netpbm/ms/pnmcolormap.ms

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.TL
Pnmcolormap User Manual
.SH 1
pnmcolormap
.LP
Updated: 23 October 2005
.br
Table Of Contents
.SH 2
NAME
.LP
pnmcolormap - create quantization color map for a Netpbm image
.SH 2
SYNOPSIS
.LP
\fBpnmcolormap\fR
[\fB-center\fR|\fB-meancolor\fR|\fB-meanpixel\fR]
[\fB-spreadbrightness\fR|\fB-spreadluminosity\fR]
[\fB-sort\fR]
[\fB-square\fR]
\fIncolors\fR|\fBall\fR
[\fIpnmfile\fR]
.LP
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 value.
.SH 2
DESCRIPTION
.LP
.LP
This program is part of Netpbm.
.LP
\fBpnmcolormap\fR reads a PNM or PAM image as input, chooses
\fIncolors\fR colors to best represent the image and writes a PNM
color map defining them as output.  A PAM image may actually contain
tuples of any kind, but \fBpnmcolormap\fR's concept of the tuple values
that best represent the ones present in the image may not make sense if
the tuple type isn't RGB or GRAYSCALE.  The design of the program, and
the rest of this manual, assumes the tuples represent colors.
.LP
You can use this map as input to \fBpnmremap\fR on the same input
image to quantize the colors in that image, I.e. produce a similar
image with fewer colors.  \fBpnmquant\fR does both the \fBpnmcolormap\fR
and \fBpnmremap\fR steps for you.
.LP
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
ones \fBpnmcolormap\fR generates have exactly one pixel of each color,
except where padding is necessary with the \fB-square\fR option.
.LP
The quantization method is Heckbert's "median cut".
See QUANTIZATION METHOD.
.LP
The output image is of the same format (PBM, PGM, PPM, PAM) as the
input image.  Note that a colormap of a PBM image is not very
interesting.
.LP
The colormap generally has the same maxval as the input image, but
\fBpnmcolormap\fR may reduce it if there are too many colors in the
input, as part of its quantization algorithm.
.LP
\fBpnmcolormap\fR works on a multi-image input stream.  In that
case, it produces one colormap that applies to all of the colors in
all of the input images.  All the images must have the same format,
depth, and maxval (but may have different height and width).  This is
useful if you need to quantize a bunch of images that will form a
movie or otherwise be used together -- you generally want them all to
draw from the same palette, whereas computing a colormap separately
from each image would make the same color in two images map to
different colors.  Before Netpbm 10.31 (December 2005), \fBpnmcolormap\fR
ignored any image after the first.
.LP
If you want to create a colormap without basing it on the colors in
an input image, \fBpamseq\fR, \fBppmmake\fR, and \fBpnmcat\fR can
be useful.
.SH 2
PARAMETERS
.LP
.LP
The single parameter, which is required, is the number of colors you want
in the output colormap.  \fBpnmcolormap\fR may produce a color map with slightly fewer colors than that.  You may
specify \fBall\fR to get a colormap of every color in the input image (no quantization).
.SH 2
OPTIONS
.LP
.RS
.IP "\fB-sort\fR"
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.
.IP "\fB-square\fR"
By default, \fBpnmcolormap\fR produces as the color map a PPM
image with one row and one column for each color in the colormap.
This option causes \fBpnmcolormap\fR instead to produce a PPM image
that is within one row or column of being square, with the last pixel
duplicated as necessary to create a number of pixels which is such an
almost-perfect square.
.IP "\fB-verbose\fR"
This option causes \fBpnmcolormap\fR to display messages to
Standard Error about the quantization.  
.IP "\fB-center\fR"
.IP "\fB-meancolor\fR"
.IP "\fB-meanpixel\fR"
.IP "\fB-spreadbrightness\fR"
.IP "\fB-spreadluminosity\fR"
These options control the quantization algorithm.  See QUANTIZATION METHOD.
.RE
.SH 2
QUANTIZATION METHOD
.LP
.LP
A quantization method is a way to choose which colors, being fewer
in number than in the input, you want in the output.
\fBpnmcolormap\fR uses Heckbert's "median cut" quantization
method.
.LP
This method involves separating all the colors into
"boxes," each holding 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.
.LP
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 particular box, means it is brighter in the
color component (red, green, blue) which has the largest spread in
that box.  \fBpnmcolormap\fR 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
\fB-spreadbrightness\fR and \fB-spreadluminosity\fR options.  The
default is \fB-spreadbrightness\fR.
.LP
\fBpnmcolormap\fR 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 image.
.LP
Note that in all three methods, there may be colors in the output
which do not appear in the input at all.
.LP
Select among these with the \fB-center\fR, \fB-meancolor\fR, and
\fB-meanpixel\fR options.  The default is \fB-center\fR.
.SH 2
REFERENCES
.LP
"Color Image Quantization for Frame Buffer Display" by Paul Heckbert,
SIGGRAPH '82 Proceedings, page 297.
.SH 2
SEE ALSO
.LP
\fBpnmremap\fR,
\fBpnmquant\fR,
\fBppmquantall\fR,
\fBpamdepth\fR,
\fBppmdither\fR,
\fBpamseq\fR,
\fBppmmake\fR,
\fBpnmcat\fR,
\fBppm\fR
.SH 2
HISTORY
.LP
.LP
Before Netpbm 10.15 (April 2003), \fBpnmcolormap\fR used a lot
more memory for large images because it kept the entire input image in
memory.  Now, it processes it a row at a time, but because it
sometimes must make multiple passes through the image, it first copies
the input into a temporary seekable file if it is not already in a seekable
file.
.LP
\fBpnmcolormap\fR first appeared in Netpbm 9.23 (January 2002).
Before that, its function was available only as part of the function
of \fBpnmquant\fR (which was derived from the much older
\fBppmquant\fR).  Color quantization really has two main subfunctions, so
Netpbm 9.23 split it out into two separate programs:
\fBpnmcolormap\fR and \fBpnmremap\fR and then Netpbm 9.24 replaced
\fBpnmquant\fR with a program that simply calls \fBpnmcolormap\fR and
\fBpnmremap\fR.
.SH 2
AUTHOR
.LP
Copyright (C) 1989, 1991 by Jef Poskanzer.
.br
\l'5i'
.SH 2
Table Of Contents
.LP
.IP \(bu
NAME
.IP \(bu
SYNOPSIS
.IP \(bu
DESCRIPTION
.IP \(bu
PARAMETERS
.IP \(bu
OPTIONS
.IP \(bu
QUANTIZATION METHOD
.IP \(bu
REFERENCES
.IP \(bu
SEE ALSO
.IP \(bu
HISTORY
.IP \(bu
AUTHOR
.LP

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.