# pnmquant - quantize the colors in a Netpbm image to a smaller set - man - [phpMan]

> **TLDR:** Quantize the colors in a PNM image into a smaller set.
>
- Generate an image using only `n_colors` or less colors as close as possible to the input image:
  `pnmquant {{n_colors}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`

*Source: tldr-pages*

---

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

## NAME
       pnmquant - quantize the colors in a Netpbm image to a smaller set


## SYNOPSIS
       **pnmquant   **[**-center**|**-meancolor**|**-meanpixel**]   [**-floyd**|**-fs**]   [**-nofloyd**|**-nofs**]  [**-spreadbright‐**
       **ness**|**-spreadluminosity**] {[**-norandom**]|[**-randomseed=_**n_]} _ncolors_ [_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 equals signs between
       an option name and its value.



## DESCRIPTION
       This program is part of [**Netpbm**(1)](https://www.chedong.com/phpMan.php/man/Netpbm/1/markdown).

       **pnmquant **reads a PNM image as input.  It chooses _ncolors_ colors to best represent the  image,
       maps the existing colors to the new ones, and writes a PNM image as output.

       This program is simply a combination of **pnmcolormap **and **pnmremap**, where the colors of the in‐
       put  are  remapped  using  a color map which is generated from the colors in that same input.
       The options have the same meaning as in those programs.  See their  documentation  to  under‐
       stand **pnmquant**.

       You may actually get fewer than **ncolors **colors in the output because
         the method **pnmcolormap **uses to choose the best set of colors for the
         image is not the same as the method **pnmremap **uses to determine the
         best color from the set to represent an individual color.  For example,
         **pnmcolormap **may include salmon in the color map as the best
         representative of a pink pixel in the input and include coral in the color
         map as the best representative of an actual coral pixel in the input.  But
         **pnmremap **is free to use any color in the color map to represent that
         pink pixel and would find coral is a closer match for pink than salmon and
         therefore use coral for pink.  **pnmremap **might not use salmon
         for _any_ pixel.

       This waste of a slot in the color map is a consequence of the approximate
         method **pnmcolormap **uses in order to compute the color map with a
         practical amount of computation.



### Running pnmcolormap and pnmremap Separately
       It  is  much faster to call **pnmcolormap **and **pnmremap **directly than to run **pnmquant**.  You save
       the overhead of the Perl interpreter and creating two extra processes.  **pnmquant  **is  just  a
       convenience.

       Here is an example of the relationship between the programs:

       This:

           $ pnmquant 256 myimage.pnm >/tmp/colormap.pnm >myimage256.pnm


       does essentially this:

           $ pnmcolormap 256 myimage.pnm >/tmp/colormap.pnm
           $ pnmremap -mapfile=/tmp/colormap.pnm myimage.pnm >myimage256.pnm



## OPTIONS
       In  addition  to  the options common to all programs based on libnetpbm (most notably **-quiet**,
       see [ Common Options](index.html#commonoptions) ), **pnmquant **recognizes the following command line options:


### Options Passed to pnmcolormap
       These options control the selection of the palette.  They are options to [**pnmcolormap**(1)](https://www.chedong.com/phpMan.php/man/pnmcolormap/1/markdown).



### -center

### -meancolor

### -meanpixel

### -spreadbrightness

### -spreadluminosity



### Options Passed to pnmremap
       These options control which color from the palette the program uses to
         replace a pixel of a certain color from the input.  They are options to [**pnmremap**(1)](https://www.chedong.com/phpMan.php/man/pnmremap/1/markdown).



### -floyd

### -fs

### -nofloyd

### -nofs

### -norandom

### -randomseed

### -norandom



## HISTORY
       **pnmquant **did not exist before Netpbm 9.21 (January 2001).  Before that, **ppmquant **did the same
       thing, but only on PPM images.  **ppmquant **continues to exist, but is only  a  front  end  (for
       name compatibility) to **pnmquant**.

### -version 


### -norandom 


## SEE ALSO
       [**pnmcolormap**(1)](https://www.chedong.com/phpMan.php/man/pnmcolormap/1/markdown), [**pnmremap**(1)](https://www.chedong.com/phpMan.php/man/pnmremap/1/markdown), [**pnmquantall**(1)](https://www.chedong.com/phpMan.php/man/pnmquantall/1/markdown), [**pamdepth**(1)](https://www.chedong.com/phpMan.php/man/pamdepth/1/markdown), [**ppmdither**(1)](https://www.chedong.com/phpMan.php/man/ppmdither/1/markdown), [**ppmquant**(1)](https://www.chedong.com/phpMan.php/man/ppmquant/1/markdown), [**pnm**(1)](https://www.chedong.com/phpMan.php/man/pnm/1/markdown)

## 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/pnmquant.html>**

netpbm documentation                      09 February 2019                   _Pnmquant_ _User_ [_Manual_(1)](https://www.chedong.com/phpMan.php/man/Manual/1/markdown)
