1Pamarith User Manual(0)                                Pamarith User Manual(0)
2
3
4

NAME

6       pamarith - perform arithmetic on two Netpbm images
7
8

SYNOPSIS

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

DESCRIPTION

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 (but see below - the functions  are  defined
46       in ways that you can effectively e.g. add real numbers).  The operation
47       is performed on two tuples as follows.  The two input images must  have
48       the  same depth, or one of them must have depth one.  pamarith fails if
49       one of these is not the case.
50
51       If they have the same depth, pamarith simply carries out the arithmetic
52       one  sample at a time.  I.e. if at a particular position the left input
53       image contains the tuple (s1,s2,...,sN) and the right input image  con‐
54       tains  the  tuple (t1,t2,...tN), and the function is f, then the output
55       image contains the tuple (f(s1,t1),f(s2,t2),...,f(sN,tN)).
56
57       If one of the images has depth 1, the arithmetic is  performed  between
58       the  one  sample  in  that  image and each of the samples in the other.
59       I.e. if at a particular position the  left  input  image  contains  the
60       tuple  (s)  and the right input image contains the tuple (t1,t2,...tN),
61       and the function is  f,  then  the  output  image  contains  the  tuple
62       (f(s,t1),f(s,t2),...,f(s,tN)).
63
64
65   Maxval
66       The meanings of the samples with respect to the maxval varies according
67       to the function you select.
68
69       In PAM images in general, the most usual meaning of a sample  (the  one
70       that  applies  when  a PAM image represents a visual image), is that it
71       represents a fraction of some maximum.  The maxval of the image  corre‐
72       sponds  to some maximum value (in the case of a visual image, it corre‐
73       sponds to "full intensity."), and a sample value divided by the  maxval
74       gives the fraction.
75
76       For  pamarith,  this  interpretation  applies to the regular arithmetic
77       functions: -add, -subtract, -multiply, -divide, -difference,  -minimum,
78       -maximum,  -mean,  and  -compare.   For  those, you should think of the
79       arguments and result as numbers in the range [0,1).   For  example,  if
80       the  maxval  of  the  left  argument image is 100 and the maxval of the
81       right argument image is 200 and the maxval of the output image is  200,
82       and  the  left  sample value in an -add calculation is 50 and the right
83       sample is 60, the actual calculation is 50/100 + 60/200 = 160/200,  and
84       the output sample value is 160.
85
86       For these functions, pamarith makes the output image's maxval the maxi‐
87       mum of the two input maxvals, except with -compare, where pamarith uses
88       an output maxval of 2.  (Before Netpbm 10.14 (February 2003), there was
89       no exception for -compare; in 10.14, the exception was  just  that  the
90       maxval  was  at  least 2, and sometime between 10.18 and 10.26 (January
91       2005), it changed to being exactly 2).
92
93       If the result of a calculation falls outside the range [0, 1), pamarith
94       clips it -- i.e.  considers it to be zero or 1-.
95
96       In many cases, where both your input maxvals are the same, you can just
97       think of the operation  as  taking  place  between  the  sample  values
98       directly,  with no consideration of the maxval except for the clipping.
99       E.g. an -add of sample value 5 to sample value 8  yields  sample  value
100       13.
101
102       But  with -multiply, this doesn't work.  Say your two input images have
103       maxval 255, which means the output image also has maxval 255.  Consider
104       a  location  in  the  image where the input sample values are 5 and 10.
105       You might think the multiplicative product of those would yield  50  in
106       the  output.   But pamarith carries out the arithmetic on the fractions
107       5/255 and 10/255.  It multiplies those together and  then  rescales  to
108       the  output  maxval,  giving a sample value in the output PAM of 50/255
109       rounded to the nearest integer: 0.
110
111       With the bit string operations, the maxval has a whole different  mean‐
112       ing.  The operations in question are: -and, -or, -nand, -nor, -xor, and
113       -shiftleft, -shiftright.
114
115       With these, each sample value in one or both input images, and  in  the
116       output  image, represents a bit string, not a number.  The maxval tells
117       how wide the bit string is.  The maxval must be a full binary count  (a
118       power  of  two minus one, such as 0xff) and the number of ones in it is
119       the width of the bit string.  For  the  dyadic  bit  string  operations
120       (that's  everything  but the shift functions), the maxvals of the input
121       images must be the same and pamarith makes the  maxval  of  the  output
122       image the same.
123
124       For the bit shift operations, the output maxval is the same as the left
125       input maxval.  The right input image (which contains the shift  counts)
126       can  have any maxval and the maxval is irrelevant to the interpretation
127       of the samples.  The sample value is the actual shift count.  But  it's
128       still required that no sample value exceed the maxval.
129
130
131   The Operations
132       Most of the operations are obvious from the option name.  The following
133       paragraphs cover those that aren't.
134
135       -subtract subtracts a value in the right input image from  a  value  in
136       the left input image.
137
138       -difference calculates the absolute value of the difference.
139
140       -multiply does an ordinary arithmetic multiplication, but tends to pro‐
141       duce nonobvious results because of the way pamarith  interprets  sample
142       values.  See Maxval ⟨#maxval⟩ .
143
144       -divide  divides  a  value  in the left input image by the value in the
145       right input image.  But like -multiply, it tends to produce  nonobvious
146       results.  Note that pamarith clipping behavior makes this of little use
147       when the left argument (dividend) is greater than  the  right  argument
148       (divisor)  --  the  result  in  that case is always the maxval.  If the
149       divisor is 0, the result is the maxval.  This option was new in  Netpbm
150       10.30 (October 2005).
151
152       -compare produces the value 0 when the value in the left input image is
153       less than the value in the right input image, 1  when  the  values  are
154       equal, and 2 when the left is greater than the right.
155
156       If  the  maxvals  of  the  input images are not identical, pamarith may
157       claim two values are not equal when in fact they are,  because  of  the
158       precision  with  which  it does the arithmetic.  However, it will never
159       say A is greater than B if A is less than B.
160
161       -compare was new in Netpbm 10.13 (December 2002).
162
163       -and, -nand, -or, -nor, and -xor consider the input and  output  images
164       to  contain  bit  strings; they compute bitwise logic operations.  Note
165       that if the maxval is 1, you can also look at these as logic operations
166       on boolean input values.  See section Maxval ⟨#maxval⟩  for the special
167       meaning of maxval with respect to bit string operations such as these.
168
169       -shiftleft and -shiftright consider the left  input  image  and  output
170       image to contain bit strings.  They compute a bit shift operation, with
171       bits falling off the left or right  end  and  zeroes  shifting  in,  as
172       opposed to bits off one end to the other.  The right input image sample
173       value is the number of bit positions to shift.
174
175       Note that the maxval (see Maxval ⟨#maxval⟩ ) determines  the  width  of
176       the frame within which you are shifting.
177
178
179   Notes
180       If you want to apply a unary function, e.g. "halve", to a single image,
181       use pamfunc.
182
183

SEE ALSO

185       pamfunc(1), pamsummcol(1),  pamsumm(1),  pnminvert(1),  pambrighten(1),
186       ppmdim(1), pnmconvol(1), pamdepth(1), pnmpsnr(1), pnm(1), pam(1)
187
188
189

HISTORY

191       pamarith replaced pnmarith in Netpbm 10.3 (June 2002).
192
193       In Netpbm 10.3 through 10.8, though, pamarith was not backward compati‐
194       ble because it required the input images to be of the  same  depth,  so
195       you  could  not  multiply  a PBM by a PPM as is often done for masking.
196       (It was not intended at the time that pnmarith would  be  removed  from
197       Netpbm  --  the  plan  was  just  to rewrite it to use pamarith; it was
198       removed by mistake).
199
200       But starting with Netpbm 10.9 (September  2002),  pamarith  allows  the
201       images to have different depths as long as one of them has depth 1, and
202       that made it backward compatible with pnmarith.
203
204       The original pnmarith did not have the -mean option.
205
206       The -compare option was added in Netpbm 10.13 (December 2002).
207
208       The bit string operations were added in Netpbm 10.27 (March 2005).
209
210       The -divide option was added in Netpbm 10.30 (October 2005).
211

DOCUMENT SOURCE

213       This manual page was generated by the Netpbm tool 'makeman'  from  HTML
214       source.  The master documentation is at
215
216              http://netpbm.sourceforge.net/doc/pamarith.html
217
218netpbm documentation            03 January 2015        Pamarith User Manual(0)
Impressum