PNMCOLORMAP(1)

πŸ“¦
version 11.13.03 Β· 5 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– pnmcolormap β€” bestie edition πŸ’–

okay so real talk, this whole thing is from the Pnmcolormap User Manual, which lives in section 1 of the General Commands Manual (that's the manual name, she's fancy like that πŸ’…). pull up a chair, get a snack, we're going to quantize some colors together and it's gonna be iconic.

✨ NAME ✨

pnmcolormap β€” create quantization color map for a Netpbm image 🎨

✨ SYNOPSIS ✨

pnmcolormap

[-center|-meancolor|-meanpixel]

[-spreadbrightness|-spreadluminosity]

[-splitpixelct|-splitcolorct|-splitspread]

[-sort]

[-square]

[-verbose]

[-debug]

ncolors|all

[pnmfile]

✨ DESCRIPTION ✨

bestie. listen. this program is part of Netpbm(1) β€” like, one of the family, we're all connected 🫢.

so what pnmcolormap does is it reads a PNM or PAM image as input, chooses ncolors colors that best represent that image, and writes a PNM color map defining them as output. and yes, a PAM image can literally contain tuples of any kind, but the program's whole concept of "which tuple values best represent the ones in the image" might just... not make sense if the tuple type isn't RGB or GRAYSCALE 😭. the design of the program β€” and the rest of this manual, honestly β€” just assumes the tuples represent colors. that's the vibe, that's the assumption, periodt.

so the way you'd use this: you take that map and feed it into pnmremap on the same input image, and boom β€” you've quantized the colors in that image, i.e. produced a similar image with fewer colors 🌈. and if doing two steps sounds like too much work (valid), pnmquant does both the pnmcolormap and pnmremap steps for you. slay.

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 pnmcolormap generates have exactly one pixel of each color, except where padding is necessary with the -square option.

the quantization method is Heckbert's "median cut" πŸ”ͺ β€” see QUANTIZATION METHOD below, it's a whole moment.

The output image is of the same format (PBM, PGM, PPM, PAM) as the input image. Not me pointing out that a colormap of a PBM image is... not very interesting 😭 β€” I'm just saying what the manual says.

the colormap generally has the same maxval as the input image, but pnmcolormap may reduce it if there are too many colors in the input, as part of its quantization algorithm. she does what she has to do πŸ’….

okay and here's a big one: pnmcolormap 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 β€” flexible queen 🌸). 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. chaotic. so anyway: before Netpbm 10.31 (December 2005), pnmcolormap ignored any image after the first. ancient behavior, we don't do that anymore πŸ’€.

and if you want to create a colormap without basing it on the colors in an input image? pamseq, ppmmake, and pamcat can be useful πŸŽ€.

✨ PARAMETERS ✨

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 (she's an overachiever who's also honest about the results πŸ™ˆ).

You may specify all to get a colormap of every color in the input image (no quantization). When you specify all, the function is essentially the same as that of ppmhist -map. and fun fact: ppmhist is much older. respect your elders ✨.

✨ OPTIONS ✨

In addition to the options common to all programs based on libnetpbm (most notably -quiet, see Common Options), pnmcolormap recognizes the following command line options:

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. flexible bestie behavior πŸ’….

  • -sort β€” this causes the output colormap to be sorted by the red component intensity, then the green, then the blue in ascending order. heads up: this is an insertion sort, so it is not very fast on large colormaps 😭. but sorting is useful because it allows you to compare two sets of colors. worth it sometimes.
  • -square β€” by default, pnmcolormap produces as the color map a PPM image with one row and with one column for each color in the colormap. this option causes pnmcolormap 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 πŸŸͺ.
  • -verbose β€” this option causes pnmcolormap to display messages to Standard Error about the quantization.
  • -debug β€” this option causes pnmcolormap to display messages to Standard Error about internal workings πŸ”.
  • -center
  • -meancolor
  • -meanpixel
  • -spreadbrightness
  • -spreadluminosity
  • -splitpixelct
  • -splitcolorct
  • -splitspread

these options control the quantization algorithm. see QUANTIZATION METHOD β€” that's where the tea is β˜•.

✨ QUANTIZATION METHOD ✨

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 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 then choose one color to represent each box. it's giving organizational queen πŸ“¦βœ¨.

There are three ways pnmcolormap can choose the box to split in each step:

  • Split the box containing the most pixels. This is the default, and you can select it explicitly with option -splitpixelct.
  • Split the box containing the most colors. This appears to be useful for academic purposes only 😭. Select this with option -splitcolorct.
  • Split the box containing the largest color spread. Select this with option -splitspread. This can produce a better result for small details with colors not found elsewhere in the image πŸ‘€.

-splitpixelct, -splitcolorct, and -splitspread were new in Netpbm 10.88 (September 2019). Before that, pnmcolormap always splits the box containing the most pixels. history, bestie πŸ“œ.

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. 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 -spreadbrightness. 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 pnmcolormap generates the same color map πŸ”₯. Before Netpbm 11.03 (June 2023), the distribution would depend upon what the system's qsort function does with multiple equal values, so pnmcolormap may produce slightly different results on different systems. chaotic era, glad we left it.

pnmcolormap 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.

select among these with the -center, -meancolor, and -meanpixel options. the default is -center πŸ’….

note that in all three methods, there may be colors in the output which do not appear in the input at all. wild, I know.

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 pnmremap 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 pnmcolormap chose to represent some other box, and in fact the color pnmcolormap chose to represent Box B may not appear in the pnmremap output at all. πŸ’€ messy but that's the algorithm.

✨ REFERENCES ✨

"Color Image Quantization for Frame Buffer Display" by Paul Heckbert, SIGGRAPH '82 Proceedings, page 297. πŸ“š the source material, the moment, the blueprint.

✨ SEE ALSO ✨

pnmremap(1), pnmquant(1), ppmquantall(1), pamgetcolor(1), pamdepth(1), ppmdither(1), pamseq(1), ppmmake(1), pamcat(1), ppm(1) πŸ¦‹

✨ HISTORY ✨

Before Netpbm 10.15 (April 2003), pnmcolormap 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 πŸ‘‘ efficiency era.

pnmcolormap first appeared in Netpbm 9.23 (January 2002) ✨. Before that, its function was available only as part of the function of pnmquant (which was derived from the much older ppmquant). Color quantization really has two main subfunctions, so Netpbm 9.23 split it out into two separate programs: pnmcolormap and pnmremap, and then Netpbm 9.24 replaced pnmquant with a program that simply calls pnmcolormap and pnmremap. glow up story honestly 🌈.

✨ AUTHOR ✨

Copyright (C) 1989, 1991 by Jef Poskanzer. 🫢

✨ DOCUMENT SOURCE ✨

This manual page was generated by the Netpbm tool makeman from HTML source. The master documentation is at

http://netpbm.sourceforge.net/doc/pnmcolormap.html

and that's the whole page, bestie πŸ’– β€” this came to you straight from the netpbm documentation, dated 21 February 2023, and yeah, it's literally titled Pnmcolormap User Manual(1) because of course it is πŸ’… go quantize something gorgeous βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from