2.3 Image Arithmetic
Beware of arithmetic overflow or underflow on pixel values. Pixels are unsigned
and have a limited number of bits (typically 8 for
greyscale or 8 bits per color R-G-B). For example. 128+129=256 which overflows to 1.
Hence an operation may need numerical scaling
of all pixel values as part of the calculation.
- Addition - pixelwise addition:
image1 + image2 (or constant)
- Subtraction - pixelwise subtraction:
image1 - image2 (or constant)
- Difference - pixelwise difference:
abs(image1 - image2 (or constant))
- Multiplication - pixelwise multiplication:
image1 * image2 (or constant)
- Division - pixelwise addition:
image / image (or constant)
- Blending - linear combination of two images:
r*image1 + (1-r)*image2, 0<r<1.0
- Logical - pixelwise logical operations between two binary images:
AND, NAND, OR, NOR, XOR, XNOR, NOT (one image)
The difference operation, absolute value of pixel by pixel difference, is the best operation for finding differences between compex images which differ in a small way.
For binary images the XOR operation is used.
It is much easier to use "JASC Paint Shop Pro" for these operations, rather than
use Photoshop.