# phpman > man > pnmremap(1)

> **TLDR:** Replace the colors in a PNM image.
>
- Replace the colors in an image with those in the specified color palette:
  `pnmremap {{-ma|-mapfile}} {{path/to/palette_file.ppm}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`
- Use Floyd-Steinberg dithering for representing colors missing in the color palette:
  `pnmremap {{-ma|-mapfile}} {{path/to/palette_file.ppm}} {{-fs|-floyd}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`
- Use the first color in the palette for representing colors missing in the color palette:
  `pnmremap {{-ma|-mapfile}} {{path/to/palette_file.ppm}} {{-fi|-firstisdefault}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`
- Use the specified color for representing colors missing in the color palette:
  `pnmremap {{-ma|-mapfile}} {{path/to/palette_file.ppm}} {{-m|-missingcolor}} {{color}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`

*Source: tldr-pages*

---

[pnmremap(1)](https://www.chedong.com/phpMan.php/man/pnmremap/1/markdown)                            General Commands Manual                           [pnmremap(1)](https://www.chedong.com/phpMan.php/man/pnmremap/1/markdown)



## NAME
       pnmremap - replace colors in a PPM image with colors from another set


## SYNOPSIS
       **pnmremap**  [**-floyd**|**-fs**|**-nfloyd**|**-nofs**]  [**-firstisdefault**] [**-verbose**] [**-mapfile=**_mapfile_] [**-miss**‐‐
       **ingcolor=**_color_] [_pnmfile_]

       All options can be abbreviated to their shortest unique prefix.  You may use two hyphens  in‐
       stead  of  one  to designate an option.  You may use either white space or an equals sign be‐
       tween an option name and its value.


## DESCRIPTION
       **pnmremap** replaces the colors in an input image with those from a colormap you specify.  Where
       a  color  in  the input is not in the colormap, you have three choices: 1) choose the closest
       color from the colormap; 2) choose the first color from the colormap; 3) use a  color  speci‐
       fied  by  a  command  option.   (In this latter case, if the color you specify is not in your
       color map, the output will not necessarily contain only colors from the colormap).

       Two reasons to do this 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.

       To reduce colors, you can generate the colormap with **ppmcolormap**.  Example:

### ppmcolormap testimg.ppm 256 >colormap.ppm
### ppmremap -map=colormap.ppm testimg.ppm
       **>reduced**___**testimg.ppm**

       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  sup‐
       posed  to  know the 216 "web safe" colors which are essentially all the colors you can repre‐
       sent in a PPM image with a maxval of 5.  So you can do this:

### ppmcolors 5 >websafe.ppm
       **ppmremap** **-map=webafe.ppm** **testimg.ppm** **>websafe**___**testimg.ppm**

       The output image has the same type and maxval as the map file.



## PARAMETERS
       There is one parameter, which is required:  The file specifcation of the input PNM file.


       **OPTIONS**

### -floyd -fs -nofloyd -nofs
              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, through a map 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.

              **-fs** is a synomym for **-floyd**.  **-nofs** is a synonym for **-nofloyd**.

              The default is **-nofloyd**.


### -firstisdefault
              This  affects  what  happens with a pixel in the input image whose color is not in the
              map file.  If you specify neither **-firstisdefault** nor **-missingcolor**, **pnmremap**  chooses
              for  the output the color in the map which is closest to the color in the input.  With
              **-firstisdefault**, **pnmremap** instead uses the first color in the colormap.

              If you specify **-firstisdefault**, the maxval of your input must match the maxval of your
              colormap.


### -missingcolor=
              This  affects  what  happens with a pixel in the input image whose color is not in the
              map file.  If you specify neither **-firstisdefault** nor **-missingcolor**, **pnmremap**  chooses
              for  the output the color in the map which is closest to the color in the input.  With
              **-missingcolor**, **pnmremap** uses _color_.  _color_ need not be in the colormap.

              If you specify **-missingcolor**, the maxval of your input must match the maxval  of  your
              colormap.


### -verbose
              Display helpful messages about the mapping process.



## SEE ALSO
       [**pnmcolormap**(1)](https://www.chedong.com/phpMan.php/man/pnmcolormap/1/markdown),  [**ppmcolors**(1)](https://www.chedong.com/phpMan.php/man/ppmcolors/1/markdown),  [**pnmquant**(1)](https://www.chedong.com/phpMan.php/man/pnmquant/1/markdown),  [**ppmquantall**(1)](https://www.chedong.com/phpMan.php/man/ppmquantall/1/markdown),  [**pnmdepth**(1)](https://www.chedong.com/phpMan.php/man/pnmdepth/1/markdown), [**ppmdither**(1)](https://www.chedong.com/phpMan.php/man/ppmdither/1/markdown), **pp**‐‐
       [**mquant**(1)](https://www.chedong.com/phpMan.php/man/mquant/1/markdown), [**ppm**(5)](https://www.chedong.com/phpMan.php/man/ppm/5/markdown)


## AUTHOR
       Copyright (C) 1989, 1991 by Jef Poskanzer.  Copyright (C) 2001 by Bryan Henderson.



                                           01 January 2002                               [pnmremap(1)](https://www.chedong.com/phpMan.php/man/pnmremap/1/markdown)
