.TL Pnmremap User Manual .SH 1 pnmremap .LP Updated: 01 January 2002 .br Table Of Contents .SH 2 NAME .LP pnmremap - replace colors in a PNM image with colors from another set .SH 2 SYNOPSIS .LP \fBpnmremap\fR \fB-mapfile=\fR\fIpalettefile\fR [\fB-floyd\fR|\fB-fs\fR|\fB-nfloyd\fR|\fB-nofs\fR] [\fB-firstisdefault\fR] [\fB-verbose\fR] [\fB-missingcolor=\fR\fIcolor\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 \fBpnmremap\fR replaces the colors in an input image with those from a palette you specify. Where colors in the input are present in the palette, they just stay the same in the output. But where the input contains a color that is not in the palette, \fBpnmremap\fR gives you three choices: 1) choose the closest color from the palette; 2) choose the first color from the palette; 3) use a color specified by a command option. .LP You can also dither, which means rather than mapping pixel by pixel, \fBpnmremap\fR uses colors from the palette to try to make multi-pixel regions of the output have the same average color as the input (for another kind of dithering, see \fBppmdither\fR). .LP Two reasons to use this program are: 1) you want to reduce the number of colors in the input image; and 2) you need to feed the image to something that can handle only certain colors. .LP To reduce colors, you can generate the palette with \fBpnmcolormap\fR. .LP By default, \fBpnmremap\fR maps an input color that is not in the palette to the closest color that is in the palette. Closest means with the smallest cartesian distance in the red, green, blue brightness space (smallest sum of the squares of the differences in red, greeN, and blue ITU-R Recommedation BT.709 gamma-adjusted intensities). .LP You can instead specify a single default color for \fBpnmremap\fR to use for any color in the input image that is not in the palette. Use the \fB-missing\fR option for this. .LP You can also specify that the first color in the palette image is the default. Use the \fB-firstisdefault\fR option for this. .LP The palette is simply a PNM image. The colors of the pixels in the image are the colors in the palette. Where the pixels appear in the image, and the dimensions of the image, are irrelevant. Multiple pixels of the same color are fine. However, a palette image is typically a single row with one pixel per color. .LP If you specify \fB-missing\fR, the color you so specify is in the palette in addition to whatever is in the palette image. .LP For historical reasons, Netpbm sometimes calls the palette a "colormap." But it doesn't really map anything. \fBpnmremap\fR creates its own map, based on the palette, to map colors from the input image to output colors. .SH 3 Palette/Image Type Mismatch .LP .LP In the simple case, the palette image is of the same depth (number of planes, i.e. number of components in each tuple (pixel)) as the input image and \fBpnmremap\fR just does a straightforward search of the palette for each input tuple (pixel). In fact, \fBpnmremap\fR doesn't even care if the image is a visual image. .LP But what about when the depths differ? In that case, \fBpnmremap\fR converts the input image (in its own memory) to match the palette and then proceeds as above. .LP There are only two such cases in which \fBpnmremap\fR knows how to do the conversion: when one of them is tuple type RGB, depth 3, and the other is tuple type GRAYSCALE or BLACKANDWHITE, depth 1; and vice versa. .LP In any other case, \fBpnmremap\fR issues and error message and fails. .LP Note that as long as your input and palette images are PNM, they'll always fall into one of the cases \fBpnmremap\fR can handle. There's an issue only if you're using some exotic PAM image. .LP Before Netpbm 10.27 (March 2005), \fBpnmremap\fR could not handle the case of a palette of greater depth than the input image. (It would issue an error message and fail in that case). .LP In any case, the output image has the same tuple type and depth as the palette image. .SH 3 Multiple Image Stream .LP .LP \fBpnmremap\fR handles a multiple image input stream, producing a multiple image output stream. The input images need not be similar in any way. .LP Before Netpbm 10.30 (October 2005), \fBpnmremap\fR ignored any image after the first. .SH 3 Examples .LP .DS L pnmcolormap testimg.ppm 256 >palette.ppm pnmremap -map=palette.ppm testimg.ppm >reduced_testimg.ppm .DE .LP To limit colors to a certain set, a typical example is to create an image for posting on the World Wide Web, where different browsers know different colors. But all browsers are supposed to know the 216 "web safe" colors which are essentially all the colors you can represent in a PPM image with a maxval of 5. So you can do this: .DS L pamseq 3 5 >websafe.pam pnmremap -map=websafe.pam testimg.ppm >websafe_testimg.ppm .DE .LP Another useful palette is one for the 8 color IBM TTL color set, which you can create with .DS L pamseq 3 1 >ibmttl.pam .DE .LP If you want to quantize one image to use the colors in another one, just use the second one as the palette. You don't have to reduce it down to only one pixel of each color, just use it as is. .LP The output image has the same type and maxval as the palette image. .SH 2 PARAMETERS .LP .LP There is one parameter, which is required: The file specification of the input PNM file. .SH 2 OPTIONS .LP .RS .IP "\fB-mapfile=\fR\fIpalettefilename\fR" This names the file that contains the palette image. .LP This option is mandatory. .IP "\fB-floyd\fR" .IP "\fB-fs\fR" .IP "\fB-nofloyd\fR" .IP "\fB-nofs\fR" These options determine whether Floyd-Steinberg dithering is done. Without Floyd-Steinberg, the selection of output color of a pixel is based on the color of only the corresponding input pixel. With Floyd-Steinberg, multiple input pixels are considered so that the average color of an area tends to stay more the same than without Floyd-Steinberg. For example, if you map an image with a black, gray, gray, and white pixel adjacent, to a palette that contains only black and white, it might result in an output of black, black, white, white. Pixel-by-pixel mapping would instead map both the gray pixels to the same color. .LP Floyd-Steinberg gives vastly better results on images where unmodified quantization has banding or other artifacts, especially when going to a small number of colors such as the above IBM set. However, it does take substantially more CPU time. .LP \fB-fs\fR is a synomym for \fB-floyd\fR. \fB-nofs\fR is a synonym for \fB-nofloyd\fR. .LP The default is \fB-nofloyd\fR. .IP "\fB-firstisdefault\fR" This tells \fBpnmremap\fR to map any input color that is not in the palette to the first color in the palette (the color of the pixel in the top left corner of the palette image) .LP See DESCRIPTION. .LP If you specify \fB-firstisdefault\fR, the maxval of your input must match the maxval of your palette image. .IP "\fB-missingcolor=\fR\fIcolor\fR" This specifies the default color for \fBpnmremap\fR to map to a color in the input image that isn't in the palette. \fIcolor\fR may or may not be in the palette image; it is part of the palette regardless. .LP If you specify \fB-missingcolor\fR, the maxval of your input must match the maxval of your palette image. .IP "\fB-verbose\fR" Display helpful messages about the mapping process. .RE .SH 2 SEE ALSO .LP \fBpnmcolormap\fR, \fBpamseq\fR, \fBpnmquant\fR, \fBppmquantall\fR, \fBpamdepth\fR, \fBppmdither\fR, \fBppmquant\fR, \fBppm\fR .SH 2 AUTHOR .LP Copyright (C) 1989, 1991 by Jef Poskanzer. .br \l'5i' .SH 2 Table Of Contents .LP .IP \(bu SYNOPSIS .IP \(bu DESCRIPTION .IP \(bu Palette/Image Type Mismatch .IP \(bu Multiple Image Stream .IP \(bu Examples .LP .IP \(bu PARAMETERS .IP \(bu OPTIONS .IP \(bu SEE ALSO .IP \(bu AUTHOR .LP