Debian Codegraph @

userguide/pnmhisteq.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
2 <html><head><title>Pnmhisteq User Manual</title></head>
3 <body>
4 <h1>pnmhisteq</h1>
5 Updated: 22 March 2015
6 <br>
7 <a href="#index">Table Of Contents</a>
8
9 <h2>NAME</h2>
10
11 pnmhisteq - histogram equalize a PNM image
12
13 <h2 id="synopsis">SYNOPSIS</h2>
14
15 <b>pnmhisteq</b>
16
17 [<b>-gray</b>]
18
19 [<b>-noblack</b>]
20 [<b>-nowhite</b>]
21
22 [<b>-rmap</b> <i>pgmfile</i>]
23
24 [<b>-wmap</b> <i>pgmfile</i>]
25
26 [<b>-verbose</b>]
27
28 [<i>pnmfile</i>]
29
30
31 <h2 id="description">DESCRIPTION</h2>
32
33 <p>This program is part of <a href="index.html">Netpbm</a>.
34
35 <p><b>pnmhisteq</b> increases the contrast of a PGM or PPM image
36 through the technique of "histogram equalization."[1]
37
38 <p><b>pnmhisteq</b> computes a histogram of the luminosity of the
39 pixels in the image. It then calculates a mapping between each
40 luminosity and a new luminosity such that it spreads out intensity
41 levels around histogram peaks and compresses them at troughs. I.e.
42 it moves pixels around in the histogram so as to make it flat. It
43 applies that mapping to the input image to produce the output image.
44 The effect of this is that the image has equal numbers of pixels at each
45 possible intensity level, which means it uses the available levels of
46 intensity more efficiently and thereby has more visible detail.
47
48 <p>Mathematically, the luminosity mapping is this: Assume the pixels
49 are sorted by luminosity into <i>B</i> buckets numbered from 0 (lowest
50 luminosity) to <i>B</i>-1. <i>N[i]</i> is the number of pixels in
51 bucket <i>i</i>. <i>T</i> is the total number of pixels (sum of
52 <i>N[i]</i> over all <i>i</i>). <i>W</i> is the luminosity of white.
53
54 <p><b>pnmhisteq</b> replaces an input pixel whose luminosity falls into
55 bucket <i>j</i> with one whose luminosity is:
56
57 <pre>
58
59 j
60 ---
61 \
62 &gt; (N[i] / T) * W
63 /
64 ---
65 i=0
66 </pre>
67
68 <p>Considering a grayscale image for simplicity, this means that
69 pixels in the most luminous bucket become white. Pixels in the 10th
70 per centile of luminosity become 10% of white.
71
72 <p><b>pnmhisteq</b> maps a single luminosity in the input to a single
73 luminosity in the output. That means if pixels A and B both have luminosity
74 .2 in the input, and pixel A has luminosity .4 in the output, pixel B also has
75 luminosity .4 in the output. And since the luminosities in the input are not
76 continuous, the luminosities in the output aren't either and <b>pnmhisteq</b>
77 doesn't meet the ideal of having exactly the same number of pixels of each
78 luminosity in the output.
79
80 <p>If you're processing a related set of images, for example frames of
81 an animation, it's generally best to apply the same luminosity mapping
82 to every frame, since otherwise you'll get distracting frame-to-frame
83 changes in the brightness of objects. <b>pnmhisteq</b>'s <b>-wmap</b>
84 option allows you to save, as a PGM image, the luminosity map it
85 computes from an image. The <b>-rmap</b> option causes <b>pnmisteq</b>
86 to use such an image as its luminosity map.
87
88 <p>So you can run <b>pnmhisteq</b> with <b>-wmap</b> on a composite you
89 created with <b>pamcat</b> of the images you intend to process. Then, you can
90 run <b>pnmisteq</b> with <b>-rmap</b> on each of the individual images, using
91 the luminosity map you generated from the composite.
92
93 <p>Use <b>pnmhistmap</b> to see the result. Run a color image through
94 <b>ppmtopgm</b> first so that you see a histogram of the luminosity instead of
95 histograms of the three color components. It should generally show a flat
96 histogram. But because of the quantization effects described above, you might
97 see high bars interleaved with low bars, with the local average being flat.
98 To see local averages, use the <b>-width</b> option of <b>pnmhistmap</b>.
99
100
101 <h2 id="options">OPTIONS</h2>
102
103 <p>In addition to the options common to all programs based on libnetpbm
104 (most notably <b>-quiet</b>, see <a href="index.html#commonoptions">
105 Common Options</a>), <b>pnmhisteq</b> recognizes the following
106 command line options:
107
108 <p>You can abbreviate any option to its shortest unique prefix.
109
110 <dl compact>
111 <dt><b>-gray</b>
112
113 <dd>When processing a color image, only gray pixels (those with identical
114 red, green, and blue values) are included in the histogram and
115 modified in the output image. This is a special purpose option
116 intended for images where the actual data are gray scale, with color
117 annotations you don't want modified. Weather satellite images that
118 show continent outlines in color are best processed using this option.
119 The option has no effect when the input is a graymap.
120
121 <dt><b>-noblack</b>
122
123 <dd>Do not include black pixels in the equalization. The black pixels in the
124 output are exactly the black pixels in the input and the number of black
125 pixels does not affect the color of any other pixels.
126
127 <p>Sometimes, black isn't as much a color as a background or annotation for
128 the real colors, so you want to treat it specially this way. Think of a
129 picture of stars, which is nearly all black, but with lots of stars of
130 different brightness. You want to change the brightnesses of the stars to
131 maximize contrast between them, but if you considered the blackness to be
132 significant, all the stars would end up close to full white.
133
134 <p>This option was new in Netpbm 10.70 (March 2015).
135
136 <dt><b>-nowhite</b>
137
138 <p>Same as <b>-noblack</b>, but for the white pixels.
139
140 <p>You can use both <b>-noblack</b> and <b>-nowhite</b> if you like.
141
142 <p>This option was new in Netpbm 10.70 (March 2015).
143
144 <dt><b>-rmap</b> <i>mapfile</i>
145
146 <dd>Process the image using the luminosity map specified by the PGM
147 file <i>mapfile</i>.
148
149 The PGM image, usually created by an earlier run of <b>pnmhisteq</b>
150 with the <b>-wmap</b> option, contains a single row with number of
151 columns equal to the maxval (greatest intensity value) of the image
152 plus one. Each pixel in the image is transformed by looking up its
153 luminosity in the corresponding column in the map file (column number
154 = luminosity) and changing it to the value given by that column.
155
156 <dt><b>-wmap</b> <i>mapfile</i>
157
158 <dd>Creates a PGM file <i>mapfile</i>, containing the luminosity map
159 computed from the histogram of the input image. This map file can be
160 read on subsequent runs of <b>pnmhisteq</b> with the <b>-rmap</b>
161 option, allowing a group of images to be processed with an identical
162 map.
163
164 <dt><b>-verbose</b>
165
166 <dd>Prints the histogram and luminosity map on Standard Error.
167
168 </dl>
169
170 <h2 id="limitations">LIMITATIONS</h2>
171
172 <p>Histogram equalization is effective for increasing the visible
173 detail in scientific imagery and in some continuous-tone pictures. It
174 is often too drastic, however, for scanned halftone images, where it
175 does an excellent job of making halftone artifacts apparent. You
176 might want to experiment with <b>pnmnorm</b> and <b>pnmgamma</b> for
177 more subtle contrast enhancement.
178
179 <p>The luminosity map file supplied by the <b>-rmap</b> option must
180 have the same maxval as the input image. This is always the case when
181 the map file was created by the <b>-wmap</b> option of
182 <b>pnmhisteq</b>. If this restriction causes a problem, simply adjust
183 the maxval of the map with <b>pamdepth</b> to agree with the input
184 image.
185
186 <p>If the input is a PBM file (on which histogram equalization is an
187 identity operation), the only effect of passing the file through
188 <b>pnmhisteq</b> will be the passage of time.
189
190 <h2 id="seealso">SEE ALSO</h2>
191
192 <b><a href="pnmnorm.html">pnmnorm</a></b>,
193
194 <b><a href="pamcat.html">pamcat</a></b>,
195
196 <b><a href="pamdepth.html">pamdepth</a></b>,
197
198 <b><a href="pnmgamma.html">pnmgamma</a></b>,
199
200 <b><a href="pnm.html">pnm</a></b>,
201
202 <dl compact>
203 <dt>[1]
204
205 <dd>Russ, John C. The Image Processing Handbook. Boca Raton: CRC
206 Press, 1992. Pages 105-110.
207
208 </dl>
209
210 <hr>
211 <h2 id="index">Table Of Contents</h2>
212 <ul>
213 <li><a href="#synopsis">SYNOPSIS</a>
214 <li><a href="#description">DESCRIPTION</a>
215 <li><a href="#options">OPTIONS</a>
216 <li><a href="#limitations">LIMITATIONS</a>
217 <li><a href="#seealso">SEE ALSO</a>
218 </ul>
219 </body>
220 </html>