\ .\" This man page was generated by the Netpbm tool 'makeman' from HTML source. .\" Do not hand-hack it! If you have bug fixes or improvements, please find .\" the corresponding HTML page on the Netpbm website, generate a patch .\" against that, and send it to the Netpbm maintainer. .TH "Pnmcolormap User Manual" 1 "21 February 2023" "netpbm documentation" .SH NAME pnmcolormap - create quantization color map for a Netpbm image .UN synopsis .SH SYNOPSIS \fBpnmcolormap\fP [\fB-center\fP|\fB-meancolor\fP|\fB-meanpixel\fP] [\fB-spreadbrightness\fP|\fB-spreadluminosity\fP] [\fB-splitpixelct\fP|\fB-splitcolorct\fP|\fB-splitspread\fP] [\fB-sort\fP] [\fB-square\fP] [\fB-verbose\fP] [\fB-debug\fP] \fIncolors\fP|\fBall\fP [\fIpnmfile\fP] .UN description .SH DESCRIPTION .PP This program is part of .BR "Netpbm" (1)\c \&. .PP \fBpnmcolormap\fP reads a PNM or PAM image as input, chooses \fIncolors\fP 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\fP'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. .PP You can use this map as input to \fBpnmremap\fP on the same input image to quantize the colors in that image, I.e. produce a similar image with fewer colors. \fBpnmquant\fP does both the \fBpnmcolormap\fP and \fBpnmremap\fP steps for you. .PP 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\fP generates have exactly one pixel of each color, except where padding is necessary with the \fB-square\fP option. .PP The quantization method is Heckbert's "median cut". See .UR #quant QUANTIZATION METHOD .UE \&. .PP 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. .PP The colormap generally has the same maxval as the input image, but \fBpnmcolormap\fP may reduce it if there are too many colors in the input, as part of its quantization algorithm. .PP \fBpnmcolormap\fP 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\fP ignored any image after the first. .PP If you want to create a colormap without basing it on the colors in an input image, \fBpamseq\fP, \fBppmmake\fP, and \fBpamcat\fP can be useful. .UN parameters .SH PARAMETERS .PP The single parameter, which is required, is the number of colors you want in the output colormap. \fBpnmcolormap\fP may produce a color map with slightly fewer colors than that. You may specify \fBall\fP to get a colormap of every color in the input image (no quantization). When you specify \fBall\fP, the function is essentially the same as that of \fBppmhist -map\fP. \fBppmhist\fP is much older. .UN options .SH OPTIONS .PP In addition to the options common to all programs based on libnetpbm (most notably \fB-quiet\fP, see .UR index.html#commonoptions Common Options .UE \&), \fBpnmcolormap\fP recognizes the following command line options: .PP 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. .TP \fB-sort\fP 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. .TP \fB-square\fP By default, \fBpnmcolormap\fP produces as the color map a PPM image with one row and with one column for each color in the colormap. This option causes \fBpnmcolormap\fP 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. .TP \fB-verbose\fP This option causes \fBpnmcolormap\fP to display messages to Standard Error about the quantization..TP \fB-center\fP .TP \fB-debug\fP This option causes \fBpnmcolormap\fP to display messages to Standard Error about internal workings. .TP \fB-center\fP .TP \fB-meancolor\fP .TP \fB-meanpixel\fP .TP \fB-spreadbrightness\fP .TP \fB-spreadluminosity\fP .TP \fB-splitpixelct\fP .TP \fB-splitcolorct\fP .TP \fB-splitspread\fP These options control the quantization algorithm. See .UR #quant QUANTIZATION METHOD .UE \&. .UN quant .SH QUANTIZATION METHOD .PP A quantization method is a way to choose which colors, being fewer in number than in the input, you want in the output. \fBpnmcolormap\fP uses Heckbert's "median cut" quantization method. .PP 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. .PP There are three ways \fBpnmcolormap\fP can choose the box to split in each step: .IP \(bu Split the box containing the most pixels. This is the default, and you can select it explicitly with option \fB-splitpixelct\fP. .IP \(bu Split the box containing the most colors. This appears to be useful for academic purposes only. Select this with option \fB-splitcolorct\fP. .IP \(bu Split the box containing the largest color spread. Select this with option \fB-splitspread\fP. This can produce a better result for small details with colors not found elsewhere in the image. .PP \fB-splitpixelct\fP, \fBsplitcolorct\fP, and \fBsplitspread\fP were new in Netpbm 10.88 (September 2019). Before that, \fBpnmcolormap\fP always splits the box containing the most pixels. .PP When you split a box, you do it so each sub-box has the same number of pixels (except one sub-box has more if the full box has an odd number), with the 'greatest' pixels in one sub-box and the 'least' pixels 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\fP 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\fP and \fB-spreadluminosity\fP options. The default is \fB-spreadbrightness\fP. Where there are multiple colors of the median magnitude, they are distributed arbitrarily among between the subboxes. This arbitrary distribution is repeatable, though, for a given Netpbm version -- every invocation of \fBpnmcolormap\fP generates the same color map. Before Netpbm 11.03 (June 2023), the distribution would depend upon what the system's \fBqsort\fP function does with multiple equal values, so \fBpnmcolormap\fP may produce slightly different results on different systems. .PP \fBpnmcolormap\fP 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. .PP Select among these with the \fB-center\fP, \fB-meancolor\fP, and \fB-meanpixel\fP options. The default is \fB-center\fP. .PP Note that in all three methods, there may be colors in the output which do not appear in the input at all. .PP Also note that the color chosen to represent the colors in Box A the best may also represent a color in Box B better than the color chosen to represent the colors in Box B the best. This is true for various measures of goodness of representation of one color by another. In particular, if you use \fBpnmremap\fP to map the colors in the very image that you used to create the color map to the colors in that colormap, the colors in Box B will often map to the color \fBpnmcolormap\fP chose to represent some other box and in fact the color \fBpnmcolormap\fP chose to represent Box B may not appear in the \fBpnmremap\fP output at all. .UN references .SH REFERENCES "Color Image Quantization for Frame Buffer Display" by Paul Heckbert, SIGGRAPH '82 Proceedings, page 297. .UN seealso .SH SEE ALSO .BR "pnmremap" (1)\c \&, .BR "pnmquant" (1)\c \&, .BR "ppmquantall" (1)\c \&, .BR "pamgetcolor" (1)\c \&, .BR "pamdepth" (1)\c \&, .BR "ppmdither" (1)\c \&, .BR "pamseq" (1)\c \&, .BR "ppmmake" (1)\c \&, .BR "pamcat" (1)\c \&, .BR "ppm" (1)\c \& .UN history .SH HISTORY .PP Before Netpbm 10.15 (April 2003), \fBpnmcolormap\fP 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. .PP \fBpnmcolormap\fP first appeared in Netpbm 9.23 (January 2002). Before that, its function was available only as part of the function of \fBpnmquant\fP (which was derived from the much older \fBppmquant\fP). Color quantization really has two main subfunctions, so Netpbm 9.23 split it out into two separate programs: \fBpnmcolormap\fP and \fBpnmremap\fP and then Netpbm 9.24 replaced \fBpnmquant\fP with a program that simply calls \fBpnmcolormap\fP and \fBpnmremap\fP. .UN author .SH AUTHOR Copyright (C) 1989, 1991 by Jef Poskanzer. .SH DOCUMENT SOURCE This manual page was generated by the Netpbm tool 'makeman' from HTML source. The master documentation is at .IP .B http://netpbm.sourceforge.net/doc/pnmcolormap.html .PP