# phpman > man > pnmhisteq(1)

> **TLDR:** Histogram-equalize a PNM image.
>
- Increase the contrast of a PNM image using histogram equalization:
  `pnmhisteq {{path/to/input.pnm}} > {{path/to/output.pnm}}`
- Only modify grey pixels:
  `pnmhisteq {{-g|-grey}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`
- Do not include black or white pixels in the histogram equalization:
  `pnmhisteq -no{{black|white}} {{path/to/input.pnm}} > {{path/to/output.pnm}}`

*Source: tldr-pages*

---

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



## NAME
       pnmhisteq - histogram equalise a portable anymap

## SYNOPSIS
       **pnmhisteq** [**-gray**] [**-rmap** _pgmfile_] [**-wmap** _pgmfile_] [**-verbose**] [_pnmfile_]

## DESCRIPTION
       **pnmhisteq**  increases  the  contrast  of a portable graymap or pixmap through the technique of
       _histogram_ _equalisation_[1].  A histogram of the luminance of pixels in the  map  is  computed,
       from  which  a transfer function is calculated which spreads out intensity levels around his‐
       togram peaks and compresses them at troughs.  This has the effect of using the available lev‐
       els of intensity more efficiently and thereby increases the detail visible in the image.

       Mathematically, if _N[i]_ is the number of pixels of luminosity _i_ in the image and _T_ is the to‐
       tal number of pixels, luminosity _j_ is replaced by:

                j
               ---
               \
                >   N[i] / T

               ---
               i=0

       If you're processing a related set of images, for example frames of an animation, it's gener‐
       ally  best  to  apply  the same intensity map to every frame, since otherwise you'll get dis‐
       tracting frame-to-frame changes in the brightness of objects.  **pnmhisteq**'s **-wmap**  option  al‐
       lows you to save, as a portable graymap, the luminosity map computed from an image (usually a
       composite of the images you intend to process created with **pnmcat**).   Then,  you  can  subse‐
       quently  process  each  of  the individual images using the luminosity map saved in the file,
       supplied with the **-rmap** option.

## OPTIONS
### -gray
                 blue  values) are included in the histogram and modified in the output image.  This
                 is a special purpose option intended for images where  the  actual  data  are  gray
                 scale,  with  colour annotations you don't want modified.  Weather satellite images
                 that show continent outlines in colour are best processed using this  option.   The
                 option has no effect when the input is a graymap.

### -rmap
                 Process  the  image using the luminosity map specified by the portable graymap _map__‐
                 _file._  The graymap, usually created by an earlier run of **pnmhisteq** with  the  **-wmap**
                 option,  contains a single row with number of columns equal to the _maxval_ (greatest
                 intensity) of the image.  Each pixel in the image is transformed by looking up  its
                 luminosity in the corresponding column in the map file and changing it to the value
                 given by that column.

### -wmap
                 Creates a portable graymap, _mapfile,_ containing the luminosity  map  computed  from
                 the  histogram of the input image.  This map file can be read on subsequent runs of
                 **pnmhisteq** with the **-rmap** option, allowing a group of images to be processed with an
                 identical map.

### -verbose

       All flags can be abbreviated to their shortest unique prefix.

## BUGS
       Histogram  equalisation  is effective for increasing the visible detail in scientific imagery
       and in some continuous-tone pictures.  It is often too drastic, however, for scanned halftone
       images, where it does an excellent job of making halftone artifacts apparent.  You might want
       to experiment with **pgnnorm**, **ppmnorm**, and **pnmgamma** for more subtle contrast enhancement.

       The luminosity map file supplied by the **-rmap** option must have the same _maxval_ as  the  input
       image.   This is always the case when the map file was created by the **-wmap** option of **pnmhis**‐‐
       **teq**.  If this restriction causes a problem, simply adjust the _maxval_ of the map with **pnmdepth**
       to agree with the input image.

       If  the  input  is a PBM file (on which histogram equalisation is an identity operation), the
       only effect of passing the file through **pnmhisteq** will be the passage of time.

## SEE ALSO
       [**pgmnorm**(1)](https://www.chedong.com/phpMan.php/man/pgmnorm/1/markdown), [**pnm**(5)](https://www.chedong.com/phpMan.php/man/pnm/5/markdown), [**pnmcat**(1)](https://www.chedong.com/phpMan.php/man/pnmcat/1/markdown), [**pnmdepth**(1)](https://www.chedong.com/phpMan.php/man/pnmdepth/1/markdown), [**pnmgamma**(1)](https://www.chedong.com/phpMan.php/man/pnmgamma/1/markdown), [**pnmnorm**(1)](https://www.chedong.com/phpMan.php/man/pnmnorm/1/markdown)

       [1]  Russ, John C.  The Image Processing Handbook.   Boca  Raton:  CRC  Press,  1992.   Pages
            105-110.

## AUTHOR
                         Copyright (C) 1995 by John Walker (<kelvin@fourmilab.ch>).
                                  WWW home page: <http://www.fourmilab.ch/>

       Permission  to  use, copy, modify, and distribute this software and its documentation for any
       purpose and without fee is hereby granted, without  any  conditions  or  restrictions.   This
       software is provided ``as is'' without express or implied warranty.



                                            19 March 1995                               [pnmhisteq(1)](https://www.chedong.com/phpMan.php/man/pnmhisteq/1/markdown)
