1Pnmhisteq User Manual(0)                              Pnmhisteq User Manual(0)
2
3
4

NAME

6       pnmhisteq - histogram equalize a PNM image
7
8

SYNOPSIS

10       pnmhisteq
11
12       [-gray]
13
14       [-rmap pgmfile]
15
16       [-wmap pgmfile]
17
18       [-verbose]
19
20       [pnmfile]
21
22
23

DESCRIPTION

25       This program is part of Netpbm(1).
26
27       pnmhisteq  increases  the  contrast  of  a PGM or PPM image through the
28       technique of 'histogram equalization.'[1]
29
30       pnmhisteq computes a histogram of the luminosity of the pixels  in  the
31       image.   It then calculates a mapping between each luminosity and a new
32       luminosity such that it spreads out intensity levels  around  histogram
33       peaks  and compresses them at troughs.  I.e.  it moves pixels around in
34       the histogram so as to make it flat.  It applies that  mapping  to  the
35       input  image  to  produce the output image.  The effect of this is that
36       the image has equal numbers of pixels at each possible intensity level,
37       which  means it uses the available levels of intensity more efficiently
38       and thereby has more visible detail.
39
40       Mathematically, the luminosity mapping is this: Assume the  pixels  are
41       sorted by luminosity into B buckets numbered from 0 (lowest luminosity)
42       to B-1.  N[i] is the number of pixels in bucket i.  T is the total num‐
43       ber of pixels (sum of N[i] over all i).  W is the luminosity of white.
44
45       pnmhisteq  replaces an input pixel whose luminosity falls into bucket j
46       with one whose luminosity is:
47
48
49             j
50            ---
51            \
52             > (N[i] / T) * W
53            /
54            ---
55            i=0
56
57       Considering a grayscale image for simplicity, this means that pixels in
58       the  most luminous bucket become white.  Pixels in the 10th per centile
59       of luminosity become 10% of white.
60
61       pnmhisteq maps a single luminosity in the input to a single  luminosity
62       in the output.  That means if pixels A and B both have luminosity .2 in
63       the input, and pixel A has luminosity .4 in the output,  pixel  B  also
64       has  luminosity  .4  in  the output.  And since the luminosities in the
65       input are not continuous, the luminosities in the output aren't  either
66       and  pnmhisteq doesn't meet the ideal of having exactly the same number
67       of pixels of each luminosity in the output.
68
69       If you're processing a related set of images, for example frames of  an
70       animation,  it's generally best to apply the same luminosity mapping to
71       every frame, since  otherwise  you'll  get  distracting  frame-to-frame
72       changes  in the brightness of objects.  pnmhisteq's -wmap option allows
73       you to save, as a PGM image, the luminosity map  it  computes  from  an
74       image.   The  -rmap  option causes pnmisteq to use such an image as its
75       luminosity map.
76
77       So you can run pnmhisteq with -wmap on a  composite  you  created  with
78       pnmcat of the images you intend to process.  Then, you can run pnmisteq
79       with -rmap on each of the individual images, using the  luminosity  map
80       you generated from the composite.
81
82       Use  pnmhistmap  to see the result.  Run a color image through ppmtopgm
83       first so that you see a histogram of the  luminosity  instead  of  his‐
84       tograms of the three color components.  It should generally show a flat
85       histogram.  But due to the quantization effects  described  above,  you
86       might  see  high bars interleaved with low bars, with the local average
87       being  flat.   To  see  local  averages,  use  the  -width  option   of
88       pnmhistmap.
89
90
91

OPTIONS

93       You can abbreviate any option to its shortest unique prefix.
94
95
96
97       -gray  When  processing  a  color  image,  only gray pixels (those with
98              identical red, green, and blue values) are included in the  his‐
99              togram and modified in the output image.  This is a special pur‐
100              pose option intended for images where the actual data  are  gray
101              scale,  with color annotations you don't want modified.  Weather
102              satellite images that show continent outlines in color are  best
103              processed  using this option.  The option has no effect when the
104              input is a graymap.
105
106
107       -rmap mapfile
108              Process the image using the luminosity map specified by the  PGM
109              file mapfile.
110
111              The  PGM  image,  usually created by an earlier run of pnmhisteq
112              with the -wmap option, contains a single row with number of col‐
113              umns equal to the maxval (greatest intensity value) of the image
114              plus one.  Each pixel in the image is transformed by looking  up
115              its luminosity in the corresponding column in the map file (col‐
116              umn number = luminosity) and changing it to the value  given  by
117              that column.
118
119
120       -wmap mapfile
121              Creates  a  PGM file mapfile, containing the luminosity map com‐
122              puted from the histogram of the input image.  This map file  can
123              be  read  on subsequent runs of pnmhisteq with the -rmap option,
124              allowing a group of images to be  processed  with  an  identical
125              map.
126
127
128       -verbose
129              Prints the histogram and luminosity map on Standard Error.
130
131
132
133

LIMITATIONS

135       Histogram  equalization  is effective for increasing the visible detail
136       in scientific imagery and in  some  continuous-tone  pictures.   It  is
137       often  too drastic, however, for scanned halftone images, where it does
138       an excellent job of making halftone artifacts apparent.  You might want
139       to  experiment  with  pnmnorm  and  pnmgamma  for  more subtle contrast
140       enhancement.
141
142       The luminosity map file supplied by the -rmap option must have the same
143       maxval  as  the input image.  This is always the case when the map file
144       was created by the -wmap option  of  pnmhisteq.   If  this  restriction
145       causes  a problem, simply adjust the maxval of the map with pamdepth to
146       agree with the input image.
147
148       If the input is a PBM file (on which histogram equalization is an iden‐
149       tity  operation), the only effect of passing the file through pnmhisteq
150       will be the passage of time.
151
152

SEE ALSO

154       pnmnorm(1), pnmcat(1), pamdepth(1), pnmgamma(1), pnm(1),
155
156
157
158       [1]    Russ, John C.  The Image Processing Handbook.  Boca  Raton:  CRC
159              Press, 1992.  Pages 105-110.
160
161
162
163netpbm documentation           02 February 2010       Pnmhisteq User Manual(0)
Impressum