Chapter 6
Chapter 6
• 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:
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.
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’)
▪ In MATLAB
• functions to perform logic operations on arrays: bitand, bitor, bitxor, and bitcmp.