1Pamarith User Manual(0) Pamarith User Manual(0)
2
3
4
6 pamarith - perform arithmetic on two Netpbm images
7
8
10 pamarith -add | -subtract | -multiply | -divide | -difference | -mini‐
11 mum | -maximum | -mean | -compare | -and | -or | -nand | -nor | -xor |
12 -shiftleft | -shiftright pamfile1 pamfile2
13
14 All options can be abbreviated to their shortest unique prefix. You
15 may use two hyphens instead of one. You may separate an option name
16 and its value with white space instead of an equals sign.
17
18
20 This program is part of Netpbm(1).
21
22 pamarith reads two PBM, PGM, PPM, or PAM images as input. It performs
23 the specified binary arithmetic operation on their sample values and
24 produces an output of a format which is the more general of the two
25 input formats. The two input images must be of the same width and
26 height. The arithmetic is performed on each pair of identically
27 located tuples to generate the identically located tuple of the output.
28
29 For the purpose of the calculation, it assumes any PBM, PGM, or PPM
30 input image is the equivalent PAM image of tuple type BLACKANDWHITE,
31 GRAYSCALE, or RGB, respectively, and if it produces a PBM, PGM, or PPM
32 output, produces the equivalent of the PAM image which is the result of
33 the calculation.
34
35 The first pamfile argument identifies the 'left' argument image; the
36 second pamfile argument identifies the 'right' one.
37
38 If the output is PAM, the tuple type is the same as the tuple type of
39 the left input image.
40
41 pamarith performs the arithmetic on each pair of identically located
42 tuples in the two input images.
43
44 The arithmetic operation is in all cases fundamentally a function from
45 two integers to an integer. The operation is performed on two tuples
46 as follows. The two input images must have the same depth, or one of
47 them must have depth one. pamarith fails if one of these is not the
48 case.
49
50 If they have the same depth, pamarith simply carries out the arithmetic
51 one sample at a time. I.e. if at a particular position the left input
52 image contains the tuple (s1,s2,...,sN) and the right input image con‐
53 tains the tuple (t1,t2,...tN), and the function is f, then the output
54 image contains the tuple (f(s1,t1),f(s2,t2),...,f(sN,tN)).
55
56 If one of the images has depth 1, the arithmetic is performed between
57 the one sample in that image and each of the samples in the other.
58 I.e. if at a particular position the left input image contains the
59 tuple (s) and the right input image contains the tuple (t1,t2,...tN),
60 and the function is f, then the output image contains the tuple
61 (f(s,t1),f(s,t2),...,f(s,tN)).
62
63
64 Maxval
65 The meanings of the samples with respect to the maxval varies according
66 to the function you select.
67
68 In PAM images in general, the most usual meaning of a sample (the one
69 that applies when a PAM image represents a visual image), is that it
70 represents a fraction of some maximum. The maxval of the image corre‐
71 sponds to some maximum value (in the case of a visual image, it corre‐
72 sponds to 'full intensity.'), and a sample value divided by the maxval
73 gives the fraction.
74
75 For pamarith, this interpretation applies to the regular arithmetic
76 functions: -add, -subtract, -multiply, -divide, -difference, -minimum,
77 -maximum, -mean, and -compare. For those, you should think of the
78 arguments and result as numbers in the range [0,1). For example, if
79 the maxval of the left argument image is 100 and the maxval of the
80 right argument image is 200 and the maxval of the output image is 200,
81 and the left sample value in an -add calculation is 50 and the right
82 sample is 60, the actual calculation is 50/100 + 60/200 = 160/200, and
83 the output sample value is 160.
84
85 For these functions, pamarith makes the output image's maxval the maxi‐
86 mum of the two input maxvals, except with -compare, where pamarith uses
87 an output maxval of 2. (Before Netpbm 10.14 (February 2003), there was
88 no exception for -compare; in 10.14, the exception was just that the
89 maxval was at least 2, and sometime between 10.18 and 10.26 (January
90 2005), it changed to being exactly 2).
91
92 If the result of a calculation falls outside the range [0, 1), pamarith
93 clips it -- i.e. considers it to be zero or 1-.
94
95 In many cases, where both your input maxvals are the same, you can just
96 think of the operation as taking place between the sample values
97 directly, with no consideration of the maxval except for the clipping.
98 E.g. an -add of sample value 5 to sample value 8 yields sample value
99 13.
100
101 But with -multiply, this doesn't work. Say your two input images have
102 maxval 255, which means the output image also has maxval 255. Consider
103 a location in the image where the input sample values are 5 and 10.
104 You might think the multiplicative product of those would yield 50 in
105 the output. But pamarith carries out the arithmetic on the fractions
106 5/255 and 10/255. It multiplies those together and then rescales to
107 the output maxval, giving a sample value in the output PAM of 50/255
108 rounded to the nearest integer: 0.
109
110 With the bit string operations, the maxval has a whole different mean‐
111 ing. The operations in question are: -and, -or, -nand, -nor, -xor, and
112 -shiftleft, -shiftright.
113
114 With these, each sample value in one or both input images, and in the
115 output image, represents a bit string, not a number. The maxval tells
116 how wide the bit string is. The maxval must be a full binary count (a
117 power of two minus one, such as 0xff) and the number of ones in it is
118 the width of the bit string. For the dyadic bit string operations
119 (that's everything but the shift functions), the maxvals of the input
120 images must be the same and pamarith makes the maxval of the output
121 image the same.
122
123 For the bit shift operations, the output maxval is the same as the left
124 input maxval. The right input image (which contains the shift counts)
125 can have any maxval and the maxval is irrelevant to the interpretation
126 of the samples. The sample value is the actual shift count. But it's
127 still required that no sample value exceed the maxval.
128
129
130 The Operations
131 Most of the operations are obvious from the option name. The following
132 paragraphs cover those that aren't.
133
134 -subtract subtracts a value in the right input image from a value in
135 the left input image.
136
137 -difference calculates the absolute value of the difference.
138
139 -multiply does an ordinary arithmetic multiplication, but tends to pro‐
140 duce nonobvious results because of the way pamarith interprets sample
141 values. See Maxval ⟨#maxval⟩ .
142
143 -divide divides a value in the left input image by the value in the
144 left input image. But like -multiply, it tends to produce nonobvious
145 results. Note that pamarith clipping behavior makes this of little use
146 when the left argument (dividend) is greater than the right argument
147 (divisor) -- the result in that case is always the maxval. If the
148 divisor is 0, the result is the maxval. This option was new in Netpbm
149 10.30 (October 2005).
150
151 -compare produces the value 0 when the value in the left input image is
152 less than the value in the right input image, 1 when the values are
153 equal, and 2 when the left is greater than the right.
154
155 If the maxvals of the input images are not identical, pamarith may
156 claim two values are not equal when in fact they are, due to the preci‐
157 sion with which it does the arithmetic. However, it will never say A
158 is greater than B if A is less than B.
159
160 -compare was new in Netpbm 10.13 (December 2002).
161
162 -and, -nand, -or, -nor, and -xor consider the input and output images
163 to contain bit strings; they compute bitwise logic operations. Note
164 that if the maxval is 1, you can also look at these as logic operations
165 on boolean input values. See section Maxval ⟨#maxval⟩ for the special
166 meaning of maxval with respect to bit string operations such as these.
167
168 -shiftleft and -shiftright consider the left input image and output
169 image to contain bit strings. They compute a bit shift operation, with
170 bits falling off the left or right end and zeroes shifting in, as
171 opposed to bits off one end to the other. The right input image sample
172 value is the number of bit positions to shift.
173
174 Note that the maxval (see Maxval ⟨#maxval⟩ ) determines the width of
175 the frame within which you are shifting.
176
177
178 Notes
179 If you want to apply a unary function, e.g. "halve", to a single image,
180 use pamfunc.
181
182
184 pamfunc(1), pamsummcol(1), pamsumm(1), pnminvert(1), ppmbrighten(1),
185 ppmdim(1), pnmconvol(1), pamdepth(1), pnmpsnr(1), pnm(1), pam(1)
186
187
188
190 pamarith replaced pnmarith in Netpbm 10.3 (June 2002).
191
192 In Netpbm 10.3 through 10.8, though, pamarith was not backward compati‐
193 ble because it required the input images to be of the same depth, so
194 you could not multiply a PBM by a PPM as is often done for masking.
195 (It was not intended at the time that pnmarith would be removed from
196 Netpbm -- the plan was just to rewrite it to use pamarith; it was
197 removed by mistake).
198
199 But starting with Netpbm 10.9 (September 2002), pamarith allows the
200 images to have different depths as long as one of them has depth 1, and
201 that made it backward compatible with pnmarith.
202
203 The original pnmarith did not have the -mean option.
204
205 The -compare option was added in Netpbm 10.13 (December 2002).
206
207 The bit string operations were added in Netpbm 10.27 (March 2005).
208
209 The -divide option was added in Netpbm 10.30 (October 2005).
210
211
212
213netpbm documentation 08 April 2007 Pamarith User Manual(0)