Adv DIP Third Lecture
Adv DIP Third Lecture
Intensity Transformations
and Spatial Filtering
1
Remember?
2
Our Objective
Image Enhancement
Enhancement is the process of manipulating an
image so that the result is more suitable than the
original for a specific application.
Very subjective
Application dependent
Viewer is the ultimate judge
Classification of Image Enhancement
3X3
neighborhood
(x, y)
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
(x, y)
Enhanced
Image, f(x, y) Image, g(x, y)
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Enhancement in Spatial Domain
Neighborhood (sub-image) rolls over the entire image,
each time centering a different pixel.
For any specific location (x, y), the value of the output
image g at those coordinates is equal to the result of
applying T to the neighborhood with origin at (x, y).
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Spatial Filtering
Thresholding is a special
case of contrast stretching.
Produces a binary image
Useful in image
segmentation
Thresholding
r s
Bit Plane Slicing
The four higher order bit, especially the last two, contain
a significant amount of visually significant data.
The lower-order planes contribute to more subtle
intensity details in the image.
original
image
Bit-plane Slicing
original
image
Bit-plane Slicing
original
image
Bit-plane Slicing
1
Binary of 194 is 110000 0
original
image
Bit-plane Slicing
Original Image
Bit-plane Slicing
Image Compression
Bit planes 8 & 7 Bit planes 8, 7, 6 & 5
4
9 8 9 8
3
2 7 4 7
2
6 4 6 1
4 0 7 4
1
An image 0
Histogram:
0 1 2 3 4 5 6 7 8 9
h: 1 1 1 0 4 0 2 3 2 2
Normalized Image Histogram
9 8 9 8
2 7 4 7
6 4 6 1
4 0 7 4
An image
Histogram:
0 1 2 3 4 5 6 7 8 9
h: ? ? ? 0 ? 0 ? ? ? ?
Normalized Image Histogram
p (r k ) = nk / n
Normalized histogram is more like probabilities
9 8 9 8
2 7 4 7
6 4 6 1
4 0 7 4
An image
Histogram:
0 1 2 3 4 5 6 7 8 9
Dark
histogram(S,'Normalization','probability')
Histogram Equalization
Histogram Equalization
Histogram Equalization
Output gray
levels
L-1
Input gray
L-1 levels
Histogram Equalization
L-1
Condition 1 guarantees that
output intensity values will never
be less than corresponding input
values thus preventing artifacts
created by reversals of intensity.
L-1
Histogram Equalization
L-1
Condition 2 guarantees that the
range of output intensities is the
same as the input.
L-1
Histogram Equalization
• Let,
– pr(r): the equalized histogram of the given image
– ps(s): the equalized histogram of the output image
L-1
L-1
Histogram Equalization
s
Histogram Equalization
Histogram Equalization
Local Histogram Processing
Local Histogram Processing
Enhanced
Image f(x, y) Image g(x, y)
g ( x, y ) = T [ f ( x, y ) ]
Spatial Filtering
m = 2a + 1, n = 2b + 1
Mask Coefficients
Image f(x,y) showing coordinate
arrangement
Spatial Filtering
Image
Origin w(-1,-1) w(-1,0) w(-1,1)
R = w( −1,−1) f ( x − 1, y − 1)
w(1,-1) w(1,0) w(1,1)
+ w( −1,0) f ( x − 1, y ) +
+ w(1,0) f ( x + 1, y ) Mask Coefficients showing
+ w(1,1) f ( x + 1, y + 1) coordinate arrangement
a b
g ( x, y ) = ∑ ∑ w(s, t ) f ( x + s, y + t )
s = − at = − b
00010000
Discrete unit impulse function
Spatial Correlation
Spatial Correlation
Spatial Correlation
Spatial Correlation
Spatial Correlation
Spatial Correlation
Spatial Correlation
Spatial Correlation
Spatial Convolution
Now, Convolute 0 0 0 1 0 0 0 0 by 1 2 3 2 8
Steps
Reverse 1 2 3 2 8 to 8 2 3 2 1
Then apply correlation as mentioned in
previous slides
Spatial Convolution
Position after 4
Starting position shifts
Final position
Full padded
Way out:
– Ignoring the outside columns/rows
– Padding
• Zero padding
• Mirror padding
Smoothing Spatial Filters
Smoothing Spatial Filters
• blurring
• noise reduction
1 16
R = ∑ wi zi
9
1
R = ∑ zi
9 i =1 16 i =1
1 1 1 1 2 1
1 1
× 1 1 1 × 2 4 2
9 16
1 1 1 1 2 1
clc;
clear all;
close all;
I = imread('cameraman.tif');
figure, imshow(I);
h = fspecial('average',5); % h = fspecial('average',hsize)
localMean = imfilter(I,h,'replicate');
imshowpair(I,localMean,'montage')
Smoothing Linear Filters
Large a: 60 pixels
After applying
Original Image 3 × 3 filter
clc;
clear all;
close all;
I = imread('cameraman.tif');
figure, imshow(I);
h = fspecial('average',5); % h = fspecial('average',hsize)
localMean = imfilter(I,h,'replicate');
imshowpair(I,localMean,'montage')
T = graythresh(localMean);
BW = im2bw(localMean,T);
figure, imshow(BW);
Smoothing Non-linear Filters
Order-Statistic(Nonlinear) Filters
Nonlinear filtering
Advantage
For certain type of random noise, they provide excellent
noise reduction
Considerably less blurring effect
Particularly effective in the presence of impulse noise,
also called salt-and-pepper noise.
Median Filter
• Policy:
– Sort the values of enclosed pixels
– Select the median as output pixel level
• Example: 10 20 20
– Let, 3X3 mask size
20 100 20
25 20 15
clc;
clear all;
close all;
I = imread('cameraman.tif');
figure, imshow(I);
J = medfilt2(I,[5 5]);
%J = medfilt2(I,[m n])
figure, imshow(J);
Median Filter
clc;
clear all;
close all;
I = imread('cameraman.tif');
figure, imshow(I);
clc;
clear all;
close all;
I = imread('cameraman.tif');
figure, imshow(I);
h = fspecial('gaussian',5,0.5);
J = imfilter(I,h,'replicate');
figure, imshow(J);
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Histogram processing
Sharpening Spatial Filters
The concept of
sharpening filter
Sharpening Spatial Filters
Blurring vs Sharpening
•Blurring/smooth is done in spatial domain by pixel averaging
in a neighbors, it is a process of integration.
Smoothing Sharpening
Averaging Difference
Integration Differentiation
Image Sharpening
Derivative operator
•Image differentiation
Behavior to check
• Along gray-ramp
Properties of Derivatives
∂f change of f
=
∂x change of x
∂f f ( x + 1) − f ( x)
=
∂x x +1− x
= f ( x + 1) − f ( x)
Digital 2nd Order Derivative
∂f
change of
∂ f
2
∂x
=
∂x 2 change of x
∂ f
2
f ( x + 1) − f ( x) − ( f ( x) − f ( x − 1)
=
∂x 2
x +1− x
= f ( x + 1) + f ( x − 1) − 2 f ( x)
1st Order & 2nd Order Derivative
ramp
edge
∂f
= f ( x + 1) − f ( x)
∂x
∂2 f
= f ( x + 1) + f ( x − 1) − 2 f ( x)
∂x 2
1st Order & 2nd Order Derivative
1st Order & 2nd Order Derivative
1st Order & 2nd Order Derivative
∂f
= f ( x + 1) − f ( x)
∂x
1st Order & 2nd Order Derivative
∂f
= f ( x + 1) − f ( x)
∂x
∂2 f
= f ( x + 1) + f ( x − 1) − 2 f ( x)
∂x 2
1st Order & 2nd Order Derivative
∂ 2
f ∂ 2
f
∇ f = 2 + 2
2
∂x ∂y
∂ f ∂ f2 2
∇ f = 2 + 2
2
∂x ∂y
We know,
∂ f
2
= f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y )
∂x 2
and,
∂2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
∂y 2
The Laplacian
∂ 2
f ∂ 2
f
∇ f = 2 + 2
2
∂x ∂y
∂2 f
= f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y )
∂x 2
∂2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
∂y 2
Therefore,
∇ 2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )
The Laplacian
∇ 2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )
mask
The Laplacian
Applying the
Laplacian mask
and,
∇ 2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )
Therefore,
g ( x, y ) = f ( x, y ) − [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )]
= 5 f ( x, y ) − [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)]
Simplification of Laplacian Sharpening
g ( x, y ) = f ( x, y ) − [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y )]
= 5 f ( x, y ) − [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)]
Simplification of Laplacian Sharpening
Unsharp Masking &
Highboost Filtering
Unsharp Masking
Steps
g mask ( x, y ) = f ( x, y ) − f ( x, y )
Blurred or Unsharp or
Average image
g ( x, y ) = f ( x, y ) + k × g mask ( x, y )
Original Sharp
Image Image
Unsharp Highboost
Masking Filtering
What have we learned so far?
What have we learned so far?
After
Original
Laplacian
image
applied
Combining Spatial Filters
After
Original Laplacian added to
Laplacian
image original image
applied
Reference
Reference :
3.1, 3.2, 3.3(3.3.1, 3.3.3), 3.4(3.4.1, 3.4.2), 3.5, 3.6, 3.7
(Only the parts taught in the class)
THANK YOU!!!