# pamarith

Updated: 22 June 2002
Index

## NAME

pamarith - perform arithmetic on two Netpbm images

## SYNOPSIS

pamarith -add | -subtract | -multiply | -difference | -minimum | -maximum | -mean pnmfile1 pnmfile2

All options can be abbreviated to their shortest unique prefix. You may use two hyphens instead of one. You may separate an option name and its value with white space instead of an equals sign.

## DESCRIPTION

pamarith Reads two PBM, PGM, PPM, or PAM images as input. It performs the specified binary arithmetic operation on their sample values and produces an output of a format which is the more general of the two input formats. The two input images must be of the same width and height. The arithmetic is performed on each pair of identically located tuples to generate the identically located tuple of the output.

For the purpose of the calculation, it assumes any PBM, PGM, or PPM input image is the equivalent PAM image of tuple type BLACKANDWHITE, GRAYSCALE, or RGB, respectively, and if it produces a PBM, PGM, or PPM output, produces the equivalent of the PAM image which is the result of the calculation.

If the output is PAM, the tuple type is the same as the tuple type of the first input image.

The arithmetic operation is in all cases fundamentally a function from two integers to an integer. The operation is performed on two tuples as follows. The two input images must have the same depth, or one of them must have depth one. pamarith fails if this is not the case.

If they have the same depth, pamarith simply carries out the arithmetic one sample at a time. I.e. if at a particular position the first input image contains the tuple (s1,s2,...,sN) and the second input image contains the tuple (t1,t2,...tN), and the function is f, then the output image contains the tuple (f(s1,t1),f(s2,t2),...,f(sN,tN)).

If one of the images has depth 1, the arithmetic is performed between the one sample in that image and each of the samples in the other. I.e. if at a particular position the first input image contains the tuple (s) and the second input image contains the tuple (t1,t2,...tN), and the function is f, then the output image contains the tuple (f(s,t1),f(s,t2),...,f(s,tN)).

The output image's maxval is the maximum of the two input maxvals.

pamarith performs the arithmetic on each pair of sample values of each pair of identically located pixels in the two images, as if maxval was 1.0, black was 0.0, and a linear scale in between. pamarith considers the result to be an intensity in that same scale and represents that intensity in the output image. If the result falls outside of [0..1), pamarith clips it -- i.e. considers it to be zero or the maximum intensity representable in the output.

The "as if" maxval of 1.0 can cause an unexpected result with -multiply. Say your two input images have maxval 255, which means the output image also has maxval 255. Consider a location in the image where the input sample values are 5 and 10. You might think the multiplicative product of those would yield 50 in the output. But pamarith carries out the arithmetic as if the maxvals are 1.0, which means the input sample values are 5/255 and 10/255. It multiplies those together and then rescales to the output maxval, giving a sample value in the output PAM of 50/255.

The operator -subtract subtracts a value in the second input image from a value in the first input image.

The operator -difference calculates the absolute value of the difference.

If you want to apply a unary function, e.g. "halve", to a single image, use pamfunc.

## SEE ALSO

pamfunc, pnminvert, ppmbrighten, ppmdim, pnmconvol, pnmdepth, pnmpsnr, pnm pam

## HISTORY

pamarith replaced pnmarith in Netpbm 10.3 (June 2002).

In Netpbm 10.3 through 10.8, though, pamarith was not backward compatible because it required the input images to be of the same depth, so you could not multiply a PBM by a PPM as is often done for masking. (It was not intended at the time that pnmarith would be removed from Netpbm -- the plan was just to rewrite it to use pamarith; it was removed by mistake).

But starting with Netpbm 10.9 (September 2002), pamarith allows the images to have different depths as long as one of them has depth 1, and that made it backward compatible with pnmarith.

The original pnmarith did not have the -mean option.

## AUTHOR

Copyright (C) 1989, 1991 by Jef Poskanzer. Lightly modified by Marcel Wijkstra <wijkstra@fwi.uva.nl>. Converted to PAM by Bryan Henderson.

## Index

NAME
SYNOPSIS
DESCRIPTION
HISTORY
SEE ALSO
AUTHOR