1Pnmhisteq User Manual(0) Pnmhisteq User Manual(0)
2
3
4
6 pnmhisteq - histogram equalize a PNM image
7
8
10 pnmhisteq
11
12 [-gray]
13
14 [-rmap pgmfile]
15
16 [-wmap pgmfile]
17
18 [-verbose]
19
20 [pnmfile]
21
22
23
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 If you're processing a related set of images, for example frames of an
62 animation, it's generally best to apply the same luminosity mapping to
63 every frame, since otherwise you'll get distracting frame-to-frame
64 changes in the brightness of objects. pnmhisteq's -wmap option allows
65 you to save, as a PGM image, the luminosity map it computes from an
66 image. The -rmap option causes pnmisteq to use such an image as its
67 luminosity map.
68
69 So you can run pnmhisteq with -wmap on a composite you created with
70 pnmcat of the images you intend to process. Then, you can run pnmisteq
71 with -rmap on each of the individual images, using the luminosity map
72 you generated from the composite.
73
74
75
77 You can abbreviate any option to its shortest unique prefix.
78
79
80
81 -gray When processing a color image, only gray pixels (those with
82 identical red, green, and blue values) are included in the his‐
83 togram and modified in the output image. This is a special pur‐
84 pose option intended for images where the actual data are gray
85 scale, with color annotations you don't want modified. Weather
86 satellite images that show continent outlines in color are best
87 processed using this option. The option has no effect when the
88 input is a graymap.
89
90
91 -rmap mapfile
92 Process the image using the luminosity map specified by the PGM
93 file mapfile.
94
95 The PGM image, usually created by an earlier run of pnmhisteq
96 with the -wmap option, contains a single row with number of col‐
97 umns equal to the maxval (greatest intensity value) of the image
98 plus one. Each pixel in the image is transformed by looking up
99 its luminosity in the corresponding column in the map file (col‐
100 umn number = luminosity) and changing it to the value given by
101 that column.
102
103
104 -wmap mapfile
105 Creates a PGM file mapfile, containing the luminosity map com‐
106 puted from the histogram of the input image. This map file can
107 be read on subsequent runs of pnmhisteq with the -rmap option,
108 allowing a group of images to be processed with an identical
109 map.
110
111
112 -verbose
113 Prints the histogram and luminosity map on Standard Error.
114
115
116
117
119 Histogram equalization is effective for increasing the visible detail
120 in scientific imagery and in some continuous-tone pictures. It is
121 often too drastic, however, for scanned halftone images, where it does
122 an excellent job of making halftone artifacts apparent. You might want
123 to experiment with pnmnorm and pnmgamma for more subtle contrast
124 enhancement.
125
126 The luminosity map file supplied by the -rmap option must have the same
127 maxval as the input image. This is always the case when the map file
128 was created by the -wmap option of pnmhisteq. If this restriction
129 causes a problem, simply adjust the maxval of the map with pamdepth to
130 agree with the input image.
131
132 If the input is a PBM file (on which histogram equalization is an iden‐
133 tity operation), the only effect of passing the file through pnmhisteq
134 will be the passage of time.
135
136
138 pnmnorm(1), pnmcat(1), pamdepth(1), pnmgamma(1), pnm(1),
139
140
141
142 [1] Russ, John C. The Image Processing Handbook. Boca Raton: CRC
143 Press, 1992. Pages 105-110.
144
145
146
147
149 Copyright (C) 1995 by John Walker (kelvin@fourmilab.ch). WWW home
150 page: http://www.fourmilab.ch/ ⟨http://www.fourmilab.ch/⟩
151
152 Permission to use, copy, modify, and distribute this software and its
153 documentation for any purpose and without fee is hereby granted, with‐
154 out any conditions or restrictions. This software is provided 'as is'
155 without express or implied warranty.
156
157
158
159netpbm documentation 10 September 2005 Pnmhisteq User Manual(0)