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

ab_dip_5_spatial_filters

The document discusses image enhancement techniques, focusing on spatial filtering methods that operate directly on pixel neighborhoods. It covers various types of filters, including smoothing, weighted smoothing, and sharpening filters like the Laplacian, highlighting their applications and limitations. Additionally, it provides examples of how different filters affect images, particularly in reducing noise and enhancing edges.

Uploaded by

sushanth.tambe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ab_dip_5_spatial_filters

The document discusses image enhancement techniques, focusing on spatial filtering methods that operate directly on pixel neighborhoods. It covers various types of filters, including smoothing, weighted smoothing, and sharpening filters like the Laplacian, highlighting their applications and limitations. Additionally, it provides examples of how different filters affect images, particularly in reducing noise and enhancing edges.

Uploaded by

sushanth.tambe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Image Enhancement

(Spatial Filtering)
Image Enhancement Revisited

• Spatial domain methods:


Operate directly on pixels
• Frequency domain methods:
Operate on the transform of an image
Neighbourhood Operations
• Operate on a
Origin y
neighbourhood of
pixels

(x, y)
Neighbourhood

x
Processing of pixels at the edges

y
Origin e e

Image f (x, y)

e e e

x
Approaches to process pixels at the edges

 Add pixels at corners with either all white or all


black pixels
 Replicate border pixels
 Truncate the image
Examples: modified image at the edges

Filtered Image:
Zeroes added

Original Filtered Image:


Image Replicate Edge Pixels
The Spatial Filtering Process
Origin x
a b c r s t
d epr
g h
f
i
* u
x
v
y
w
z
Original Image Filter
e 3*3 Filter Pixels

eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i

• Procedure is repeated for every pixel in the original image


to generate the filtered image
Smoothing Spatial Filters
Averages all of the pixels in a neighbourhood around a
central value
 Useful in reducing noise from images and for
highlighting gross detail

1 1 1

Averaging 1 1 1
A=(1/9)
filter
1 1 1
Smoothing Spatial Filtering
Origin x 1 1
54 100 208 1
1 1 1
49 106 198

45 90 185
* 1/9
1 1 1

23 42 86
54 100 208
Original Image Filter
Pixels 3*3 Smoothing
49 106 198
45 90 185
Filter
e = 1/9[106 + 54 +100 + 208 +
49 + 198 +45 + 90 + 185]
= 115
y Image f (x, y)
Smoothing Spatial Filtering
Origin x 1 1
23 42 86 1
1 1 1
54 100 208

49 106 198
* 1/9
1 1 1

23 42 86

54 100 208
Original Image Filter
49 106 198 Pixels 3*3 Smoothing
45 90 185 Filter
e = 1/9[23+42+86+54+100+208
+49+106+198+]
= 94.77  95
y Image f (x, y)
Smoothing Spatial Filtering
Origin x

95
115

y Filtered Image
Original Image
Image filtered with 3x3 mask
Image filtered with 5x5 mask
Image filtered with 9x9 mask
Image filtered with 15x15 mask
Image filtered with 35x35 mask
Image Smoothing Example

Original image

Sharpness/details begin
to disappear with increase 3x3
in size of mask

5x5

9x9

15x15

35x35
Limitations of averaging filter

• Leads to blurring of image


• Attenuates impulse noise
• Does not remove impulse noise
Weighted Smoothing Filters

 Elements of mask have


different weights. 1 2 1
 Provides more effective
smoothing 2 4 2
A= (1/16)
 Pixels closer to the
central pixel are more
important 1 2 1
 Often referred to as a
weighted averaging Weighted
averaging filter
Application of average filter
(smoothening & thresholding)

Original Image
Application of average filter
(smoothening & thresholding)

Original Image Smoothed Image


Application of average filter
(smoothening & thresholding)

Original Image Smoothed Image Thresholded Image


5×5 mask G(x,y) =255, if f(x,y)>120
=0, otherwise
• Removes finer details
• Thresholding separates gross details
Simple Neighbourhood Operations

• Min: minimum in the neighbourhood


• Max: maximum in the neighbourhood
• Median: midpoint value of the set
Minimum and Maximum Filter

2 3 6

1 1 8 Image after
2 3 6 minimum filter
7 4 5
1 2 8 

7 4 5 2 3 6
Image after
Image Before filter
1 8 8 Maximum filter

7 4 5
Median filter

2 3 6
 [2 3 6 1 2 8 7 4 5]  sort in ascending
1 2 8
[1 2 2 3 4 5 6 7 8]
7 4 5
Image Before filter 2 3 6

1 4 8 After filter

7 4 5
Image with salt and pepper /impulse noise
After Averaging Filter (blurs)
After Median Filter
Averaging Filter Vs. Median Filter

Original Image Image After Image After


With Noise Averaging Filter Median Filter

Median filter works better than an averaging filter for


salt and pepper noise
Example: Spatial filters

Image matrix is given below. Determine the effect of


1. 3x3 and 5x5 averaging filters
2. 3x3 weighted averaging filter
3. 3x3 Minimum, maximum and median filters

45 56 42 63 54
20 47 56 28 53
63 59 26 38 47
67 36 27 48 51
43 36 42 65 43
Example: Spatial filters

Image matrix is given below. Determine the effect of


1. 3x3 and 5x5 averaging filters
2. 3x3 weighted averaging filter
3. 3x3 Minimum, maximum and median filters

45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 47 56 28 53
63 59 26 38 47 63 59 26 38 47
67 36 27 48 51 67 36 27 48 51
43 36 42 65 43 43 36 42 65 43

First location of filter for 3x3 filter Next location of mask for 3x3 filter
Example: Spatial filters

Image matrix is given below. Determine the effect of


1. 3x3 and 5x5 averaging filters and minimum filter
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 46 46 45 53
1 1 1
63 59 26 38 47 63 44 41 42 47
67 36 27 48 51
* (1/9) 1 1 1 =
67 44 42 43 51
1 1 1
43 36 42 65 43 43 36 42 65 43

45 56 42 63 54 1 1 1 1 1 45 56 42 63 54
20 47 56 28 53 1 1 1 1 1 20 47 56 28 53
63 59 26 38 47 *(1/25) 1 1 1 1 1 = 63 59 46 38 47
67 36 27 48 51 1 1 1 1 1 67 36 27 48 51
43 36 42 65 43 1 1 1 1 1 43 36 42 65 43
Example: Spatial filters

Image matrix is given below. Determine the effect of


1. 3x3 weighted averaging filters
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 47 45 44 53
1 2 1
63 59 26 38 47 63 47 39 40 47
67 36 27 48 51
* (1/16) 2 4 2 =
67 43 38 44 51
1 2 1
43 36 42 65 43 43 36 42 65 43

45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 20 26 26 53
min(3x3) =
63 59 26 38 47 63 20 26 26 47
67 36 27 48 51 67 26 26 26 51
43 36 42 65 43 43 36 42 65 43
Example: Spatial filters

Image matrix is given below. Determine the effect of


1. 3x3 weighted averaging filters
45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 63 63 63 53
63 59 26 38 47 max(3x3) 63 67 59 56 47
=
67 36 27 48 51 67 67 65 65 51
43 36 42 65 43 43 36 42 65 43

45 56 42 63 54 45 56 42 63 54
20 47 56 28 53 20 47 47 47 53
median(3x3) =
63 59 26 38 47 63 47 38 47 47
67 36 27 48 51 67 42 38 43 51
43 36 42 65 43 43 36 42 65 43
Sharpening Spatial Filters
 Remove blurring in images
 Highlight transition in intensity (edges)
 Used in electronic printing, medical
imaging, industrial inspection etc.
Uses spatial differentiation
 Differentiation measures the rate of
change of a function
The Laplacian operator

image Laplacian Filter Laplacian Filter

a b d 0 1 0 0 -1 0

e f g 1 -4 1 -1 4 -1

h i j 0 1 0 0 -1 0
0 -1 0

or -1 4 -1

0 -1 0
Example of Laplacian

0 0 4 0 0 0 -1 0
0 0 4 0 0
4 4 4 4 4 -1 4 -1
0 0 4 0 0
*
0 0 4 0 0 0 -1 0

0 0 4 0 0
0 0
4 4
= 0 0
0 0 4 0 0
The Laplacian
Highlights edges and other discontinuities

Original Laplacian Laplacian


Image Filtered Image Filtered Image
Scaled for Display
The Laplacian
Highlights edges and other discontinuities

Original Laplacian Laplacian


Image Filtered Image Filtered Image
Scaled for Display
The Laplacian
Highlights edges and other discontinuities

Original Laplacian Laplacian


Image Filtered Image Filtered Image
Scaled for Display
Image Enhancement using Laplacian

- =
Original Positive Laplacian Sharpened
Image Filtered Image Image

Sharpened image has enhanced edges and fine


detail
Image Enhancement using Laplacian
Image Enhancement using the Lapacian

0 -1 0

-1 5 -1

0 -1 0
Simplified Image Enhancement

original enhanced
Variants of Laplacian
Simple Laplacian
Variant of Laplacian Considers
Considers horizontal
diagonals of edges
and vertical edges

0 1 0 1 1 1
1 -4 1 1 -8 1
0 1 0 1 1 1

-1 -1 -1

-1 8 -1

-1 -1 -1
Example Variant of Laplacian

1 4 5 2 7 -1 -1 -1
0 4 0 6 2
3 2 1 0 2 -1 8 -1
7 5 2 3 1
*
4 3 2 5 1 -1 -1 -1

1 4 5 2 7
0 16 -24 29 2
3 -6 -14 -17 2
=
7 -16 -5 10 1
4 3 2 5 1
Prewitt Operators

Gx Gy

-1 -1 -1 -1 0 1
0 0 0 -1 0 1
1 1 1 -1 0 1

To detect horizontal or vertical edges


Sobel Operators

Gx Gy

-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1

To detect horizontal or vertical edges


Sobel Example
Sobel filters
are typically
used for edge
detection

image Enhanced image


Example Prewitt operators

4 4 4 4 4 1 1 1
4 4 4 4 4
0 0 0 0 0 0 0 0
0 0 0 0 0
*
0 0 0 0 0 -1 -1 -1

4 4 4 4 4
4 12 12 12 4
0 12 12 12 0
= 0 0 0 0 0
0 0 0 0 0
Unsharp (smoothed) Masking and
Highboost Filtering
• Apply averaging filter to blur the original
image
• Subtract the blurred image from the original
image
• Difference is called the mask
• Add weighted mask to the original
Steps for image sharpening
• gmask(x,y) = f(x,y) - fb(x,y)
fb represents blurring
• g(x,y) = f(x,y) + k*gmask(x,y), where, k ≥ 0
k=1, unsharp masking
k>1 , highboost filtering
k<1 , reduces effect of unsharp mask
• g(x,y) can be <0 or >255
• Apply contrast stretching (point processing)
to cover the range 0 to 255
Highboost Filtering
Intensity along a row of image with M rows and N columns
255

edges
20

0 N-1
Highboost Filtering
Intensity along a row of image with M rows and N columns
255

edges
20

0 N-1

fb(x,y) = f(x,y) * averaging filter


Highboost Filtering
Intensity along a row of image with M rows and N columns
255

edges
20

0 N-1

fb(x,y) = f(x,y) * averaging filter

gmask(x,y) = f(x,y) - fb(x,y)


Highboost Filtering
Intensity along a row of image with M rows and N columns
255

edges
20

0 N-1

fb(x,y) = f(x,y) * averaging filter

gmask(x,y) = f(x,y) - fb(x,y)

g(x,y) = f(x,y) + k*gmask(x,y), where, k ≥ 0


Highboost Filtering

f(x,y)

k=1

k=4.5
Highboost Filtering

f(x,y)

fb(x,y) =
f(x,y)*
h(x,y)

k=1

k=4.5
Highboost Filtering

f(x,y)

fb(x,y) =
f(x,y)*
h(x,y)

gmask(x,y)=
f(x,y)- fb(x,y)

k=1

k=4.5
Highboost Filtering

f(x,y)

fb(x,y) =
f(x,y)*
h(x,y)

gmask(x,y)=
f(x,y)- fb(x,y)

f(x,y) +
k*gmask(x,y),
k=1

k=4.5
Highboost Filtering

f(x,y)

fb(x,y) =
f(x,y)*
h(x,y)

f(x,y)- fb(x,y)

f(x,y) +
k*gmask(x,y),
k=1

f(x,y) +
k*gmask(x,y),
k=4.5

You might also like