1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
\
.\" This man page was generated by the Netpbm tool 'makeman' from HTML source.
.\" Do not hand-hack it! If you have bug fixes or improvements, please find
.\" the corresponding HTML page on the Netpbm website, generate a patch
.\" against that, and send it to the Netpbm maintainer.
.TH "Pnmnorm User Manual" 0 "19 December 2014" "netpbm documentation"
.SH NAME
pnmnorm - normalize the contrast in a Netpbm image
.UN synopsis
.SH SYNOPSIS
\fBpnmnorm\fP
[\fB-bpercent=\fP\fIpercent\fP | \fB-bvalue=\fP\fIN\fP | \fB-bsingle\fP]
[\fB-wpercent=\fP\fIpercent\fP | \fB-wvalue=\fP\fIN\fP | \fB-wsingle\fP]
[\fB-midvalue=\fP\fIN\fP]
[\fB-middle=N\fP]
[\fB-maxexpand=\fP\fIpercent\fP]
[\fB-keephues\fP]
[\fB-luminosity\fP | \fB-colorvalue\fP | \fB-saturation\fP]
[\fIppmfile\fP]
.PP
All options can be abbreviated to their shortest unique prefix.
You may use two hyphens instead of one to designate an option. You
may use either white space or an equals sign between an option name
and its value.
.UN description
.SH DESCRIPTION
.PP
This program is part of
.BR "Netpbm" (1)\c
\&.
.PP
\fBpnmnorm\fP reads a PNM image (PBM, PGM, or PPM). It normalizes the
contrast by forcing the brightest pixels to white, the darkest pixels to
black, and spreading out the ones in between. It produces the same kind of
file as output. This is pretty useless for a PBM image.
.PP
The program offers two ways of spreading out the pixels in between the
darkest and brightest: linear and quadratic. In the quadratic case, you
specify some in between brightness and specify what brightness that should
become in the output. With those three constraints: the brightness that
becomes black, the brightness that becomes white, and the brightness that
becomes that middle value, \fBpnmnorm\fP computes a quadratic equation that
maps all the other brightnesses from input values to output values.
.PP
The program first determines a mapping of old brightness to new
brightness. For each possible brightness of a pixel, the program
determines a corresponding brightness for the output image.
.PP
Then for each pixel in the image, the program computes a color which has
the desired output brightness and puts that in the output. With a color
image, it is not always possible to compute such a color and retain any
semblance of the original hue, so the brightest and dimmest pixels may only
approximate the desired brightness.
.PP
For a PPM image, you have a choice of three ways to define brightness:
.IP \(bu
luminosity
.IP \(bu
color value
.IP \(bu
saturation
In the case of saturation, "brightness" is pretty much a
misnomer, but you can use the brightness analogy to see what it does.
In the analogy, bright means saturated and dark means unsaturated.
.PP
Note that all of these are different from separately normalizing
the individual color components.
.PP
An alternative way to spread out the brightnesses in an image is
\fBpnmhisteq\fP. \fBpnmhisteq\fP stretches the brightest pixels to
white and the darkest pixels to black, but rather than linearly
adjusting the ones in between, it adjusts them so that there are an
equal number of pixels of each brightness throughout the range. This
gives you more contrast than \fBpnmnorm\fP does, but can considerably
change the picture in exchange.
.UN options
.SH OPTIONS
.PP
In addition to the options common to all programs based on libnetpbm
(most notably \fB-quiet\fP, see
.UR index.html#commonoptions
Common Options
.UE
\&), \fBpnmnorm\fP recognizes the following
command line options:
.PP
By default, the darkest 2 percent of all pixels are mapped to
black, and the brightest 1 percent are mapped to white. You can
override this behavior and specify either a different percentage, or
specific brightness values to map to black and to white, or just have
the single greatest brightness map to white and the least brightness map
to black.
.TP
\fB-bpercent\fP
.TP
\fB-wpercent\fP
.TP
\fB-bvalue\fP
.TP
\fB-wvalue\fP
.sp
To specify a percentage, use the \fB-bpercent\fP and
\fB-wpercent\fP options, or you can specify the exact pixel values to
be mapped by using the \fB-bvalue\fP and \fB-wvalue\fP options.
You can get appropriate numbers for the options from
\fBppmhist\fP. If you just want to enhance the contrast, then
choose values at elbows in the histogram; e.g. if value 29 represents
3% of the image but value 30 represents 20%, choose 30 for
\fIbvalue\fP. If you want to brighten the image, then set
\fIbvalue\fP to 0 and just fiddle with \fIwvalue\fP; similarly, to
darken the image, set \fIwvalue\fP to maxval and play with
\fIbvalue\fP.
.sp
If you specify both \fB-bvalue\fP and \fB-bpercent\fP, \fBpnmnorm\fP
uses the one that produces the least change. The same goes for
\fB-wvalue\fP and \fB-wpercent\fP. (In Netpbm 10.26 (January 2005),
the \fB-bvalue\fP/\fB-wvalue\fP takes precedence, and before that,
it's a syntax error to specify both).
.sp
If you want to maximize the change instead of minimizing it, just
cascade two runs of \fBpnmnorm\fP, specifying values for the first
and percentages for the second.
.sp
\fB-bpercent\fP and \fB-wpercent\fP values are floating point
decimal. Zero is valid and is the same as \fB-bvalue=0\fP or
\fB-wvalue=\fP\fImaxval\fP, respectively.
.sp
Because there are whole numbers of pixels at each brightness,
\fBpnmnorm\fP obviously can't guarantee the exact percentage, so it
arranges that \fIat least\fP the percentage of pixels you specify
get remapped as promised.
.sp
It is possible for your \fB-bpercent\fP or \fB-wpercent\fP
to overlap your \fB-wvalue\fP or \fB-bvalue\fP, respectively. For
example, you say \fB-bpercent=20\fP and \fB-wvalue=100\fP for an
image in which only 10 percent of the pixels are darker than 100.
In that case, \fBpnmnorm\fP adjusts the percentile value as
required. In the example, it uses 99 as the black value (like
\fB-bvalue=99\fP).
.sp
It is also possible for your \fB-bpercent\fP and \fB-wpercent\fP
options to select the same brightness value for the stretch-to-white
and stretch-to-black value because of the fact that \fBpnmnorm\fP
can't subdivide a histogram cell. E.g. if an image is all brightness
100, then no matter what \fB-bpercent\fP and \fB-wpercent\fP
values you choose, it's the same as saying \fB-bvalue=100 -wvalue=100\fP.
In that case, \fBpnmnorm\fP changes one of the values by 1 to make it
legal. In the example, \fBpnmnorm\fP would either make the black
value 99 or the white value 101.
.sp
Before Netpbm 10.43 (June 2008), \fBpnmnorm\fP fails if the
\fB-wpercent\fP and/or \fB-bpercent\fP values specify an overlap.
.sp
The stretch points are further constrained by the \fB-maxexpand\fP
option. Sometimes, too much contrast is a bad thing. If your
intensities are all concentrated in the middle, \fB-bpercent=2\fP and
\fB-wpercent=1\fP might mean that an intensity of 60 gets stretched
up to 100 and intensity of 20 gets stretched down to zero, for a
range expansion of 150% (from a range of 40 to a range of 100). That
much stretching means two adjacent pixels that used to differ in
intensity by 4 units now differ by 10, and that might be unsightly.
.TP
\fB-bsingle\fP
.sp
To specify that the single least brightness in the image should stretch to
black in the output, specify \fB-bsingle\fP. To specify that the single
greatest brightness in the image should stretch to white in the output,
specify \fB-wsingle\fP. \fB-bsingle\fP and \fB-wsingle\fP were new in
Netpbm 10.69 (December 2014).
.TP
\fB-maxexpand\fP
.sp
So that you can put a limit on the amount of expansion without
having to examine the image first, there is the \fB-maxexpand\fP
option. It specifies the maximum expansion you will tolerate, as an
additional percentage. In the example above, you could say
\fB-maxexpand=50\fP to say you want the range to expand by at most
50%, regardless of your other options. \fBpnmnorm\fP figures out
what intensity to stretch to full intensity and what intensity to
stretch to zero intensity as described above, and then raises the
former and lowers the latter as needed to limit the expansion to the
amount you specified.
.sp
When \fBpnmnorm\fP limits the expansion because of \fB-maxexpand\fP,
it tells you about it with a message like this:
.nf
limiting expansion of 150% to 50%
.fi
.sp
In any case, \fBpnmnorm\fP tells you exactly what expansion it's
doing, like this:
.nf
remapping 25..75 to 0..100
.fi
.sp
Before Netpbm 10.26 (December 2004), it was not valid to specify both
\fB-bvalue\fP and \fB-bpercent\fP or \fB-wvalue\fP and \fB-wpercent\fP.
.sp
\fB-maxexpand\fP was new in Netpbm 10.32 (February 2006).
.TP
\fB-keephues\fP
.sp
This option says to keep each pixel the same hue as
it is in the input; just adjust its brightness. You normally want this;
the only reason it is not the default behavior is backward compatibility
with a design mistake.
.sp
By default, \fBpnmnorm\fP normalizes contrast in each component
independently (except that the meaning of the \fB-wpercent\fP and
\fB-bpercent\fP options are based on the overall brightnesses of the
colors, not each component taken separately). So if you have a color
which is intensely red but dimly green, \fBpnmnorm\fP would make the
red more intense and the green less intense, so you end up with a
different hue than you started with.
.TP
\fB-midvalue=\fP\fIN\fP
.TP
\fB-middle=\fP\fIN\fP
.sp
When you specify \fB-midvalue=\fP\fIN\fP, \fBpnmnorm\fP uses a quadratic
function to map old brightnesses to new ones, making sure that an old
brightness of \fIN\fP becomes 50% bright in the output. You can override
that 50% default with \fB-middle\fP. The value of \fB-middle\fP is a
floating point number in the range 0 through 1 with 0 being full darkness and
1 full brightness. If your \fB-midvalue\fP and \fB-middle\fP indicate an
ambiguous or impossible quadratic function (e.g. \fB-midvalue\fP is the same
as \fB-bvalue\fP, so an infinite number of quadratic functions
fit), \fBpnmnorm\fP just ignores your \fB-midvalue\fP and maps linearly.
\fB-midvalue\fP and \fB-middle\fP were new in Netpbm 10.57 (December 2011).
.sp
If you specify \fB-keephues\fP, \fBpnmnorm\fP would likely leave
this pixel alone, since its overall brightness is medium.
.sp
\fB-keephues\fP can cause clipping, because a certain color may be
below a target intensity while one of its components is saturated.
Where that's the case, \fBpnmnorm\fP uses the maximum representable
intensity for the saturated component and the pixel ends up with less
overall intensity, and a different hue, than it is supposed to have.
.sp
This option is meaningless on grayscale images.
.sp
When you \fIdon't\fP specify \fB-keephues\fP, the
\fB-luminosity\fP, \fB-colorvalue\fP, and \fB-saturation\fP options
affect the transfer function (which is the same for all three RGB
components), but are meaningless when it comes to applying the
transfer function (since it is applied to each individual RGB
component).
.sp
Before Netpbm 9.25 (March 2002), there was no \fB-keephues\fP option.
.TP
\fB-luminosity\fP
.TP
\fB-colorvalue\fP
.TP
\fB-saturation\fP
.sp
\fB-luminosity\fP, \fB-colorvalue\fP, and \fB-saturation\fP determine
what property of the pixels \fBpnmnorm\fP normalizes. I.e., what kind of
brightness. You cannot specify more than one of these.
.sp
The \fB-luminosity\fP option says to use the luminosity (i.e. the
"Y" in the YUV or YCbCr color space) as the pixel's brightness. The
luminosity is a measure of how bright a human eye would find the color,
taking into account the fact that the human eye is more sensitive to some
RGB components than others.
.sp
This option is default.
.sp
This option is meaningless on grayscale images.
.sp
Before Netpbm 10.28 (August 2005), there was no \fB-luminosity\fP option,
but its meaning was still the default.
.sp
Before Netpbm 10.28 (August 2005), there was no \fB-colorvalue\fP option.
.sp
The \fB-colorvalue\fP option says to use the color value (i.e. the
"V" in the HSV color space) as the pixel's brightness. The
color value is the gamma-adjusted intensity of the most intense RGB
component.
.sp
This option is meaningless on grayscale images.
.sp
Before Netpbm 10.28 (August 2005), there was no \fB-colorvalue\fP option.
.sp
The \fB-saturation\fP option says to use the saturation (i.e. the
"S" in the HSV color space) as the pixel's brightness. The
saturation is the ratio of the intensity of the most intense RGB
component to the difference between the intensities of the most and least
intense RGB component (all intensities gamma-adjusted).
.sp
In this case, "brightness" is more of a metaphor than anything.
"bright" means saturated and "dark" means unsaturated.
.sp
This option is meaningless on grayscale images.
.sp
Before Netpbm 10.28 (August 2005), there was no \fB-colorvalue\fP option.
.UN seealso
.SH SEE ALSO
.BR "pnmhisteq" (1)\c
\&,
.BR "pamlevels" (1)\c
\&,
.BR "ppmhist" (1)\c
\&,
.BR "pgmhist" (1)\c
\&,
.BR "pambrighten" (1)\c
\&,
.BR "ppmdim" (1)\c
\&,
.BR "pnmgamma" (1)\c
\&,
.BR "pnm" (5)\c
\&
.SH DOCUMENT SOURCE
This manual page was generated by the Netpbm tool 'makeman' from HTML
source. The master documentation is at
.IP
.B http://netpbm.sourceforge.net/doc/pnmnorm.html
.PP
|