Chapter 6
ARITHMETIC OPERATIONS: FUNDAMENTALS AND
APPLICATIONS
• Arithmetic operations involving images are typically performed on a
pixel-by-pixel basis; that is, the operation is independently applied to each
pixel in the image.
• Given a 2D array (X) and another 2D array of the same size or a
scalar (Y), the resulting array, Z, is obtained by calculating:
▪ X opn Y = Z
▪ where opn is a binary arithmetic (+, −, ×, /) operator. This section
describes each arithmetic operation in more detail, focusing on how
they can be performed and what are their typical applications.
• Addition:
▪ Addition is used to blend the pixel contents from two images or add a
constant value to pixel values of an image.
▪ Adding the contents of two monochrome images causes their contents
to blend.
▪ Adding a constant value (scalar) to an image causes an increase (or
decrease if the value is less than zero) in its overall brightness, a process
sometimes referred to as additive image offset.
▪ Adding random amounts to each pixel value is a common way to
simulate additive noise.
• Addition in MATLAB:
▪ Image Processing Toolbox (IPT) has a built-in function to add two images
or add a constant (scalar) to an image: imadd.
▪ There are two ways of dealing with this overflow issue: normalization
and truncation.
▪ Normalization consists in storing the intermediate result in a temporary
variable (W) and calculating each resulting pixel value in Z using
equation:
where f is the current pixel in W, Lmax is the maximum possible intensity
value (e.g., 255 for uint8 or 1.0 for double), g is the corresponding pixel
in Z, fmax is the maximum pixel value in W, and fmin is the minimum
pixel value in W.
▪ Truncation consists in simply limiting the results to the maximum
positive number that can be represented with the adopted data type.
▪ Example (6.1):
X = uint8([200 100 100; 0 10 50; 50 250 120])
Y = uint8([100 220 230; 45 95 120; 205 100 0]) W = uint16(X) + uint16(Y)
fmax = max(W(:))
fmin = min(W(:))
Za = uint8(255.0*double((W-fmin))/double((fmax-fmin)))
Zb = imadd(X,Y)
• Subtraction:
▪ Subtraction is often used to detect differences between two images,
decrease its overall brightness, or obtain its negative.
▪ Subtracting a constant value (scalar) from an image causes a decrease in
its overall brightness, a process sometimes referred to as subtractive
image offset.
• Subtraction in MATLAB:
function to subtract one image from another, or subtract a constant from an
image: imsubtract.
function to calculate the absolute difference of two images: imabsdiff.
function for calculating the negative (complement) of an image,
imcomplement.
X = uint8([200 100 100; 0 10 50; 50 250 120])
Example 6.2:
Y = uint8([100 220 230; 45 95 120; 205 100 0])
Za = imsubtract(X,Y)
Zb = imsubtract(Y,X)
Zc = imabsdiff(Y,X)
▪ Image subtraction can also be used to obtain the negative of an image.
g = −f + Lmax
where Lmax is the maximum possible intensity value (e.g., 255 for uint8
or 1.0 for double), f is the pixel value in X, g is the corresponding pixel in
Z.
• Multiplication and Division
▪ Multiplication and division by a scalar are often used to perform
brightness adjustments on an image.
▪ In MATLAB:
• function to multiply two images or multiply an image by a constant: immultiply.
• function to divide one image into another or divide an image by a constant:
imdivide.
• Combining Several Arithmetic Operations
▪ function to perform a linear combination of two or more images:
imlincomb.
▪ In MATLAB:
X = uint8([200 100 100; 0 10 50; 50 250 120])
Y = uint8([100 220 230; 45 95 120; 205 100 0])
Z = uint8([200 160 130; 145 195 120; 105 240 150])
Sa = imdivide(imadd(X,imadd(Y,Z)),3)
a = uint16(X) + uint16(Y)
b=a+ uint16(Z)
Sb = uint8(b/3)
Sc = imlincomb(1/3,X,1/3,Y,1/3,Z,’uint8’)
LOGIC OPERATIONS: FUNDAMENTALS AND
APPLICATIONS
• Logic operations
▪ Performed in a bit-wise fashion on the binary contents of each pixel
value. The AND, XOR, and OR operators require two or more arguments,
whereas the NOT operator requires only one argument.
▪ The most common logic operations applied to binary images, using the
following convention: 1 (true) for white pixels and 0 (false) for black
pixels.
▪ The AND operation can be used to combine images for special effects
purposes.
▪ The OR operation can be used to combine images for special effects
purposes.
▪ The XOR operation is often used to highlight differences between two
monochrome images.
▪ The NOT operation extracts the binary complement of each pixel value,
which is equivalent to applying the “negative” effect on an image.
▪ In MATLAB
• functions to perform logic operations on arrays: bitand, bitor, bitxor, and bitcmp.
Important level 3 (IT, CS)
Made by Abdulrahman Salah Eldin