1Pnmconvol User Manual(0) Pnmconvol User Manual(0)
2
3
4
6 pnmconvol - general MxN convolution on a PNM image
7
8
10 pnmconvol
11
12 convolution_matrix_file [-nooffset] [pnmfile]
13
14 Minimum unique abbreviation of option is acceptable. You may use dou‐
15 ble hyphens instead of single hyphen to denote options. You may use
16 white space in place of the equals sign to separate an option name from
17 its value.
18
19
20
22 This program is part of Netpbm(1).
23
24 pnmconvol reads two PNM images as input, convolves the second using the
25 first, and writes a PNM image as output.
26
27 Convolution means replacing each pixel with a weighted average of the
28 nearby pixels. The weights and the area to average are determined by
29 the convolution matrix (sometimes called a convolution kernel), which
30 you supply by way of the PNM image in the file you identify with the
31 convolution_matrix_file argument. There are two ways pnmconvol inter‐
32 prets the PNM convolution matrix image pixels as weights: with offsets,
33 and without offsets.
34
35 The simpler of the two is without offsets. That is what happens when
36 you specify the -nooffset option. In that case, pnmconvol simply nor‐
37 malizes the sample values in the PNM image by dividing by the maxval.
38
39 For example, here is a sample convolution file that causes an output
40 pixel to be a simple average of its corresponding input pixel and its 8
41 neighbors, resulting in a smoothed image:
42
43 P2
44 3 3
45 18
46 2 2 2
47 2 2 2
48 2 2 2
49
50 (Note that the above text is an actual PGM file -- you can cut and
51 paste it. If you're not familiar with the plain PGM format, see theP‐
52 GMformatspecification[1m(1)).
53
54 pnmconvol divides each of the sample values (2) by the maxval (18) so
55 the weight of each of the 9 input pixels gets is 1/9, which is exactly
56 what you want to keep the overall brightness of the image the same.
57 pnmconvol creates an output pixel by multiplying the values of each of
58 9 pixels by 1/9 and adding.
59
60 Note that with maxval 18, the range of possible values is 0 to 18.
61 After scaling, the range is 0 to 1.
62
63 For a normal convolution, where you're neither adding nor subtracting
64 total value from the image, but merely moving it around, you'll want to
65 make sure that all the scaled values in (each plane of) your convolu‐
66 tion PNM add up to 1, which means all the actual sample values add up
67 to the maxval.
68
69 When you don't specify -nooffset, pnmconvol applies an offset, the pur‐
70 pose of which is to allow you to indicate negative weights even though
71 PNM sample values are never negative. In this case, pnmconvol sub‐
72 tracts half the maxval from each sample and then normalizes by dividing
73 by half the maxval. So to get the same result as we did above with
74 -nooffset, the convolution matrix PNM image would have to look like
75 this:
76
77 P2
78 3 3
79 18
80 10 10 10
81 10 10 10
82 10 10 10
83
84 To see how this works, do the above-mentioned offset: 10 - 18/2 gives
85 1. The normalization step divides by 18/2 = 9, which makes it 1/9 -
86 exactly what you want. The equivalent matrix for 5x5 smoothing would
87 have maxval 50 and be filled with 26.
88
89 Note that with maxval 18, the range of possible values is 0 to 18.
90 After offset, that's -9 to 9, and after normalizing, the range is -1 to
91 1.
92
93 For a normal convolution, where you're neither adding nor subtracting
94 total value from the image, but merely moving it around, you'll want to
95 make sure that all the offset, scaled values in (each plane of) your
96 convolution PNM add up to 1. That means the actual sample values, less
97 half the maxval, add up to half the maxval as in the example above.
98
99 The convolution file will usually be a PGM, so that the same convolu‐
100 tion gets applied to each color component. However, if you want to use
101 a PPM and do a different convolution to different colors, you can cer‐
102 tainly do that.
103
104 At the edges of the convolved image, where the convolution matrix would
105 extend over the edge of the image, pnmconvol just copies the input pix‐
106 els directly to the output.
107
108 The convolution computation can result in a value which is outside the
109 range representable in the output. When that happens, pnmconvol just
110 clips the output, which means brightness is not conserved.
111
112
114 The -nooffset option was new in Netpbm 10.23 (July 2004).
115
116
117
119 pnmsmooth(1), pgmmorphconv(1), pnmnlfilt(1), pgmkernel(1), pamgauss(1),
120 pnm(1)
121
122
124 Copyright (C) 1989, 1991 by Jef Poskanzer. Modified 26 November 1994
125 by Mike Burns, burns@chem.psu.edu
126
127
128
129netpbm documentation 29 June 2005 Pnmconvol User Manual(0)