0% found this document useful (0 votes)
2 views

Chapter 3 ppt part II

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter 3 ppt part II

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

1

of
39

Spatial Domain Image Processing


Part II
15
of
39
Spatial Filtering
• It refers to image operators that change the gray value at any
pixel (x,y) depending on the pixel values in a square
neighborhood centered at (x,y) using a fixed integer matrix of
the same size.
• The integer matrix is called a filter , mask, kernel or a window.
• At each pixel (x,y), the response of the filter at that pixel is
calculated using a predefined relationship (linear or nonlinear).
16
of
39
Spatial Filtering cont..

Note:
The size of mask must be odd (i.e. 3×3, 5×5,
etc.) to ensure it has acenter. The smallest
meaningful size is 3×3.
16
of
39
Spatial Filtering cont..
• Classification on the basis of linearity:
There are two types:
1. Linear Spatial Filter
2. Non-linear Spatial Filter
• General Classification:
There are two types:
1. Smoothing Spatial Filter: Smoothing filter is used for blurring and noise reduction in the image.
• Blurring is pre-processing steps for removal of small details and Noise Reduction is
accomplished by blurring.
2. Sharpening Spatial Filter: It is also known as derivative filter.
• The purpose of the sharpening spatial filter is just the opposite of the smoothing spatial filter.
• Its main focus in on the removal of blurring and highlight the edges.
• It is based on the first and second order derivative.
17
of Linear Spatial Filtering
39

• The process consists of moving the filter mask from pixel to


pixel in an image.
• At each pixel (x,y), the response is given by a sum of products
of the filter coefficients and the corresponding image pixels in
the area spanned by the filter mask.
• For the 3×3 mask shown in the previous figure, the result (or
response), R, of linear filtering is:
18
of Linear Spatial Filtering (Convolution) cont..
39

• For the 3×3 mask shown in the previous figure, the result (or response), R, of
linear filtering is:

• In general, linear filtering of an image f of size M×N with a filter mask of size
m×n is given by the expression:

• Where a = (m - 1)/2 and b = (n - l)/2. To generate a complete filtered image this


equation must be applied for x = 0,1, 2,..., M-1 and y = 0,1, 2,..., N-1.
19
of Nonlinear Spatial Filtering
39

• The operation also consists of moving the filter mask from


pixel to pixel in an image.
• The filtering operation is based conditionally on the values of
the pixels in the neighborhood, and they do not explicitly use
coefficients in the sum-of-products manner.
• For example, noise reduction can be achieved effectively with a
nonlinear filter.
• Computation of the median is a nonlinear operation.
20
of
39
Linear Spatial Filtering Example
• Example:
– Use the following 3×3mask to perform the convolution process on
theshaded pixels in the 5×5 image below. Write the filtered image.
21
of
39
Solution
22
of
39
Solution cont..
23
of
39
Spatial Filters
• Spatial filters can be classified by effect into:
1. Smoothing Spatial Filters: also called lowpass filters.
They include:
1.1 Averaging linear filters
1.2 Order-statistics nonlinear filters.
2. Sharpening Spatial Filters: also called highpass filters.
For example, the Laplacian linear filter.
24
of
39
Smoothing Spatial Filters
• are used for blurring and for noise reduction. Blurring is
used in preprocessing steps to:
– remove small details from an image prior to (large) object
extraction
– bridge small gaps in lines or curves.
• Noise reduction can be accomplished by blurring with a
linear filter and also by nonlinear filtering.
25
of
39
Averaging linear filters
• The response of averaging filter is simply the average of
the pixels contained in the neighborhood of the filter
mask.
• The output of averaging filters is a smoothed image with
reduced "sharp" transitions in gray levels.
• Noise and edges consist of sharp transitions in gray
levels.
• Thus smoothing filters are used for noise reduction;
however, they have the undesirable side effect that they
blur edges.
26
of
39
Averaging linear filters cont..

Note:
Weighted average filter has different coefficients to give more
importance (weight) to some pixels at the expense of others.
The idea behind that is to reduce blurring in the smoothing process.
27
of
39
Averaging linear filters cont..
• Averaging linear filtering of an image f of size M×N with a
filter mask of size m×n is given by the expression:

To generate a complete filtered image this equation must be applied for x = 0,1, 2,..., M-1 and y =
0,1, 2,..., N-1.
28
of Example:- Applying standard averaging filter.
39

Effect of averaging filter.


• (a) Original image.
• (b)-(f) Results of smoothing
with square averaging filter
masks of sizes n = 3,5,9,15,
and 35, respectively.
29
of
39
Averaging Filter cont..
As shown in the figure, the effects of averaging linear filter
are:
1. Blurring which is increased whenever the mask size
increases.
2. Blending (removing) small objects with the background. The
size of the mask establishes the relative size of the blended
objects.
3. Black border because of padding the borders of the original
image.
4. Reduced image quality.
30
of
39
Order-statistics filters
• are nonlinear spatial filters whose response is based on ordering
(ranking) the pixels contained in the neighborhood, and
• then replacing the value of the center pixel with the value
determined by the ranking result.
• Examples include Max, Min, and Median filters.
• It replaces the value at the center by the median pixel value in the
neighborhood, (i.e. the middle element after they are sorted).
• Median filters are particularly useful in removing impulse noise
(also known as salt-and-pepper noise). Salt = 255, pepper = 0
gray levels.
• In a 3×3 neighborhood the median is the 5th largest value, in a
5×5 neighborhood the 13th largest value, and so on.
31
of
39
Examples:- Applying Median Filter
• For example, suppose that a 3×3 neighborhood has gray levels
(10, 20, 0, 20, 255, 20, 20, 25, 15).
• These values are sorted as 0,10,15,20,20,20,20,25,255), which
results in a median of 20 that replaces the original pixel value 255
(salt noise).
32
of
39
Solution
33
of
39
Example: Effect of median filter.

(a) Image corrupted by salt & pepper


noise.
(b) Result of applying 3×3 standard
averaging filter on (a).
(c) Result of applying 3×3 median filter
on (a).

As shown in the figure, the effects of median filter are:


1. Noise reduction
2. Less blurring than averaging linear filter
34
of
39
Sharpening Spatial Filters(High Pass)

• Sharpening aims to highlight fine details (e.g. edges) in an


image, or enhance detail that has been blurred through errors or
imperfect capturing devices.
• Image blurring can be achieved using averaging filters, and
hence sharpening can be achieved by operators that invert
averaging operators.
• In mathematics, averaging is equivalent to the concept of
integration, and differentiation inverts integration. Thus,
sharpening spatial filters can be represented by partial
derivatives.
35
of Partial derivatives of digital functions
39

• The first order partial derivatives of the digital image f(x,y) are:

• The first derivative must be:


1) zero along flat segments (i.e. constant gray values).

2) non-zero at the outset of gray level step or ramp (edges or noise)


3) non-zero along segments of continuing changes (i.e. ramps).
36
of
39
Sharpening Spatial Filters
Previously we have looked at smoothing filters which
remove fine detail
Sharpening spatial filters seek to highlight fine detail
– Remove blurring from images
– Highlight edges
Sharpening filters are based on spatial differentiation
37
of
39
Spatial Differentiation
Differentiation measures the rate of change of
a function
Let’s consider a simple 1 dimensional
example
38
of
39
Spatial Differentiation

A B
39
of
39
1st Derivative
The formula for the 1st derivative of a function is as follows:

f
= f (x +1) − f (x)
x
It’s just the difference between subsequent values and
measures the rate of change of the function
40
of
39
1st Derivative (cont…)
8
7
6
5
4
3
2
1
0

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7

0 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0
8
6
4
2
0
-2
-4
-6
-8
41
of
39
2nd Derivative
The formula for the 2nd derivative of a function is as follows:
 f
2
=
f (x+ 1)+ f (x-1)-2 f (x)
2 x
Simply takes into account the values both before and after
the current value
42
of
39
Using Second Derivatives For Image Enhancement

The 2nd derivative is more useful for image enhancement


than the 1st derivative
• Stronger response to fine detail
• Simpler implementation
The first sharpening filter we will look at is the Laplacian
• Isotropic
• One of the simplest sharpening filters
• We will look at a digital implementation
43
of
39
The Laplacian
The Laplacian is defined as follows:
 f  f
2 2
 f = 2 + 2
2
 x  y
where the partial 1st order derivative in the x
direction is defined as follows:
2 f
= f (x +1, y) + f (x −1, y) − 2 f (x, y)
2 x
and in the y direction as follows:
2 f
= f (x, y +1) + f (x, y −1) − 2 f (x, y)
2 y
44
of
39
The Laplacian (cont…)
So, the Laplacian can be given as follows:
 f = [ f (x +1, y) + f (x −1, y)
2

+ f (x, y +1) + f (x, y −1)]


− 4 f (x, y)
We can easily build a filter based on this
0 1 0

1 -4 1

0 1 0
45
of
39
The Laplacian (cont…)
Applying the Laplacian to an image we get a new image
that highlights edges and other discontinuities

Original Laplacian Laplacian


Image Filtered Image Filtered Image
Scaled for Display
46
of
39
But That Is Not Very Enhanced!
The result of a Laplacian filtering
is not an enhanced image
We have to do more work in
order to get our final image
Subtract the Laplacian result
Laplacian
from the original image to Filtered Image
Scaled for Display
generate our final sharpened
enhanced image
g(x, y) = f (x, y) −  f2
47
of
39
Laplacian Image Enhancement

- =
Original Laplacian Sharpened
Image Filtered Image Image

In the final sharpened image edges and fine


detail are much more obvious
48
of
39
Laplacian Image Enhancement
49
of
39
Simplified Image Enhancement
The entire enhancement can be combined into a single
filtering operation
g(x, y) = f (x, y) −  f
2

= 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)
50
of
39
Simplified Image Enhancement (cont…)

This gives us a new filter which does the whole job for us in
one step

0 -1 0

-1 5 -1

0 -1 0
51
of
39
Simplified Image Enhancement (cont…)
52
of
39

Question?

You might also like