Uploaded by Kotla Nishanth

Image Filtering 1

advertisement
Computer Vision and Image Processing
– Fundamentals and Applications
M
.K
.B
hu
ya
n
Image Filtering
Course Instructor: Dr. M.K. Bhuyan
Professor
Department of Electronics and Electrical Engineering,
Indian Institute of Technology Guwahati, India.
Image Enhancement
• Image enhancement techniques:
ya
n
➢ Spatial domain methods
➢ Frequency domain methods
M
.K
.B
hu
• Spatial (time) domain techniques are techniques that
operate directly on pixels.
• Frequency domain techniques are based on modifying
the Fourier transform of an image.
M
.K
.B
hu
ya
n
Image Enhancement
Original image
Enhanced image
Enhancement: to process an image for more
suitable output for a specific application.
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
M
.K
.B
hu
ya
n
Image Subtraction
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
M
.K
.B
hu
ya
n
SPATIAL DOMAIN FILTERING
n
ya
hu
.K
.B
M
Image filtering involves
M
.K
.B
hu
ya
n
❖ Neighbourhood operation.
❖ Taking a filter mask from point to point in an
image and perform operations on pixels inside
the mask.
n
ya
hu
.K
.B
M
M
.K
.B
hu
ya
n
output image
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
Linear Filtering
In the case of linear filtering, the mask is placed over the pixel; the gray values of
the image are multiplied with the corresponding mask weights and then added up to
give the new value of the pixel.
Thus the filtered image g[m,n] is given by
 w
m ', n '
n'
.K
.B
hu
m'
f [m − m ', n − n ']
n
=
ya
g[m, n]
M
Where summations are performed over the window. The filtering window is usually
symmetric about the origin so that we can write
g[m, n]
=
 w
m ', n '
m'
n'
f [m + m ', n + n ']
Linear vs Non-Linear
Spatial Filtering Methods
M
.K
.B
hu
ya
n
• A filtering method is linear when the output is a weighted
sum of the input pixels.
• Methods that do not satisfy the above property are called
non-linear.
– e.g.,
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
Handling Pixels Close to Boundaries
pad with zeroes
hu
.K
.B
M
0 0 0 ……………………….0
ya
n
0 0 0 ……………………….0
or
Linear Spatial Filtering Methods
• Two main linear spatial filtering methods:
M
.K
.B
hu
ya
n
– Correlation
– Convolution
Correlation
w(i,j)
g(i,j)
f(i,j)
M
.K
.B
hu
ya
n
Output
Image
g ( x, y ) = w( x, y ) • f ( x, y ) =
K /2
K /2
 
s =− K /2 t =− K /2
w( s, t ) f ( x + s, y + t )
Correlation (cont’d)
M
.K
.B
hu
ya
n
Often used in applications where
we need to measure the similarity
between images or parts of
images
(e.g., pattern matching).
n
ya
hu
.K
.B
M
Illustration of Spatial filtering
11
10
50
8
9
5
6
0
0
0
0
7
9
11
0
0
10
50
8
0
0
9
5
0
0
0
0
M
.K
.B
hu
Original Image
0
n
9
ya
7
1/9
1
1
1
1
1
1
1
1
1
3 x 3 Averaging
Mask
6
0
Input Image after zero padding
0
0
Movement of Spatial Mask
1/9
0
0
0
1/9
0
1/9
7
1/9
9
11
0
1/9
0
1/9
10
1/9
50
8
0
0
9
5
6
0
0
0
0
0
0
n
1/9
1/9
0
ya
1/9
1/9
1/9
0
hu
1/9
1/9
1/9
.K
.B
1/9
1/9
M
1/9
0 x 1/9 + 0 x 1/9 + 0 x 1/9 + 0 x 1/9 + 7 x 1/9 + 9 x 1/9 + 0 x 1/9 + 10 x 1/9 + 50 x 1/9
= 8.4
Movement of Spatial Mask (Cont..)
1/9
1/9
0
1/9
1/9
0
1/9
0
0
1/9
0
1/9
1/9
8.4
1/9
1/9
9
1/9
11
0
1/9
0
1/9
1/9
10
1/9
1/9
50
1/9
8
0
M
.K
.B
hu
ya
n
1/9
0
0
9
5
6
0
0
0
0
0
0
0 x 1/9 + 0 x 1/9 + 0 x 1/9+ 8.4 x 1/9 + 9 x 1/9 + 11 x 1/9 +10 x 1/9 +50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 1/9 + 0 x 1/9 + 0x 1/9 + 0 x 1/9
= 4.1
Movement of Spatial Mask (Cont..)
0
0
0
0
0
8.4
10.7
8.8
0
1/9
0
1/9
10.3
1/9
1/9
12.9
1/9
5.7
0
1/9
0
1/9
4.1
1/9
5
1/9
6
0
1/9
0
1/9
0
1/9
0
1/9
0
0
M
.K
.B
hu
ya
n
0
10.3 x 1/9 +12.9 x 1/9 + 5.7x 1/9 + 4.1 x 1/9 + 5 x 1/9 + 6 x 1/9 + 0 x 1/9 + 0 x 1/9 + 0 x 1/9
= 4.6
Movement of Spatial Mask (Cont..)
0
0
0
0
0
8.4
10.7
8.8
0
0
1/9
10.3
1/9
12.9
1/9
1/9
5.7
1/9
0
0
1/9
4.1
1/9
4.6
1/9
6
1/9
0
0
1/9
0
1/9
0
1/9
0
1/9
0
M
.K
.B
hu
ya
n
0
12.9 x 1/9 + 5.7 x 1/9 + 0 x 1/9 + 4.6 x 1/9 + 6 x 1/9+ 0 x 1/9 + 0 x 1/9 + 0 x 1/9 + 0 x 1/9
= 3.2
Movement of Spatial Mask (Cont..)
0
0
0
0
0
8.4
10.7
8.8
0
0
10.3
12.9
5.7
0
0
4.1
4.6
3.2
0
0
0
0
0
0
M
.K
.B
hu
ya
n
0
Result of Averaging filter
9
11
8.4
10.7
8.8
10
50
8
10.3
12.9
5.7
9
5
6
4.6
3.2
Original Image
M
.K
.B
hu
ya
n
7
4.1
Image after Spatial Averaging
Averaging Low-pass filter
An example of a linear filter is the averaging low-pass
filter. The output I of an averaging filter at any pixel
is the average of the neighbouring pixels inside the
filter mask. It can be given as f [m, n] =  w f [m + i, n + j] ,
avg
avg
i, j
j
n
i
i, j
i, j
M
.K
.B
hu
ya
where the filter mask is of size m  n and f , w are the
image pixel values and filter weights respectively.
Averaging filter can be used for blurring and noise
reduction.
• Averaging low-pass filter reduces noise.
• Large filtering window means more blurring
Averaging filter
Noisy Image
M
.K
.B
hu
ya
n
Original Image
Filtered Image
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
Low-pass filter example
M
.K
.B
hu
ya
n
• Filtered with 7X7 averaging mask
Spatial Averaging
M
.K
.B
hu
ya
n
3x3
Smoothing
filter
Original Image
Smoothened Image
Spatial Averaging
M
.K
.B
hu
ya
n
5x5
Smoothing
filter
Original Image
Smoothened Image
Smoothing Filters: Averaging
Example: extract, largest, brightest objects
M
.K
.B
hu
ya
n
15 x 15 averaging
image thresholding
Smoothing filters: Gaussian
M
.K
.B
hu
ya
n
• The weights are samples of the Gaussian function
mask size:
σ = 1.4
Smoothing filters: Gaussian (cont’d)
M
.K
.B
hu
ya
n
As σ increases, more samples must be obtained to represent the
Gaussian function accurately.
Therefore, σ controls the amount of smoothing
σ=3
M
.K
.B
hu
ya
n
Smoothing filters: Gaussian (cont’d)
n
ya
hu
.K
.B
M
Averaging vs Gaussian Smoothing
M
.K
.B
hu
ya
n
Averaging
Gaussian
n
ya
hu
.K
.B
M
High-pass filter
A high-pass filtered image can be computed as the difference between the original and a
lowpass filtered version.
High pass = Original − Lowpass
0
0
0
1
0
0
0
-
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
1/9
.K
.B
hu
ya
n
0
M
0
=
-1/9
-1/9
-1/9
-1/9
8/9
-1/9
-1/9
-1/9
-1/9
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
Unsharp (smoothed) Masking and High Boost filter
To sharpen images
subtracting an unsharp version of the
image from the original image
f s [m, n] = Af [m, n] − f av [m, n] A  1
= ( A − 1) f [m, n] + f [m, n] − f av [m, n]
M
.K
.B
hu
ya
n
= ( A − 1) f [m, n] + f high [m, n]
High boost filtering
f (m, n)
A
M
f (m, n)
.K
.B
hu
ya
n
Low pass filter
f l (m, n)
A f (m, n)
A  f (m, n) − fl (m, n)
M
.K
.B
hu
ya
n
High pass Vs High boost filtering
High pass filtered image
Original Image
High boost filtered image
n
ya
hu
.K
.B
M
A=1.4
A=1.9
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
Median Filtering
Median
filtering
M
.K
.B
hu
ya
n
Averaging
Very effective for removing “salt and pepper” noise
(i.e., random occurrences of black and white pixels).
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
255
17
20
20
20
n
15
ya
20
hu
20
M
.K
.B
18
Median
Sorted data
15 17 18 20 20 20 20 20 255
Median= 20, and 255 will be replaced by 20
n
ya
hu
.K
.B
M
M
.K
.B
hu
ya
n
Median Filtering
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
n
ya
hu
.K
.B
M
The bilateral filter is defined as: as
M
.K
.B
hu
ya
n
g(i, j) is the filtered image, and I is the original input image.
The weight w(i, j, k, l) is assigned using the spatial closeness
and the intensity difference. A pixel located at (i, j) is
denoised using its neighbouring pixels located at (k, l). The
weight is assigned to the pixel (k, l) for denoising the pixel
(i, j), and the weight is given by:
M
.K
.B
hu
ya
n
Domain kernel is given by:
Data-dependent range kernel is given by:
n
ya
hu
.K
.B
M
Bilateral Filters with various range and domain parameter values
R. C. Gonzalez and R. E. Woods, Digital Image Processing, Addison-Wesley, 2008.
M
.K
.B
hu
ya
n
FREQUENCY DOMAIN FILTERING
Download