0% found this document useful (0 votes)
13 views32 pages

Ch-2C Spatial Filteing

Uploaded by

komal.sali23
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)
13 views32 pages

Ch-2C Spatial Filteing

Uploaded by

komal.sali23
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/ 32

Image Enhancement

Using Spatial Filtering

Dr. Kiran TALELE


Son of Tulshiram & Vasumati Talele
 99 870 30 881 [email protected]

Image Enhancement by Neighbourhood


Processing : Spatial Filtering
(i) In Neighbourhood opération, Tx. function
works on a group of input pixel values
(ii) The Output pixel value at (x,y) position is
obtained by masking operation
(iii) The use of spatial mask for image processing
is called spatial filtering and the mask is
called spatial filter


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 22
2

1
Masking Operation: Consider an image F and filter mask W

F Z1 Z2 Z3 w =  w1 w2 w3  A =
=  
Z4 Z5 Z6 *  w4
 w7
w5
w8
w6  ==
w9 
R
Z7 Z8 Z9 

The response of mask is given by,

R=

Dr. Kiran TALELE 99870 30 881 [email protected] 33


3

Spatial Filtering
F(8,11)

O 1 2 3 4 5 6 7 8 9 10 11 y
O z1 z2 z3 w1 w2 w3
1
2
3
4
z4 z5 z6
z7 z8 z9
* w4 w5 w6
w7 w8 w9
5
6
7 Original Image Filter Mask
8 Pixels
The response of Filter at
A(8,11) position is given by,

A(8,11) = z1 w1 + z2 w2 +
x Input Image F z3 w3+ … + z9 w9

The above is repeated for every pixel in the original


image to generate the smoothed image
4

2
List of Spatial Filters
[I] Smoothing Linear Filters (3)
Eg. Low Pass Averaging Filter, Weighted Average Filter,
Trimmed Averaging Filter and Geometric Mean Filter
[II] Smoothing Non-Linear Filters (3)
Eg. Median, Max and Min Filter.
[III] Sharpening : First Order Derivative Filters (4)
Eg. Robert, Prewit, Sobel and Fri-Chen filter
[IV] Sharpening Second Order Derivative Filters (3)
Eg. Laplacian Filter, HPF and High Boost Filter

☆ Image Enhancement by Spatial Filtering 5


5

[ I ] Smoothing Linear Filters


(1) Low Pass Averaging Filter

(i) LPF attenuates High frequency Components and allows


to pass LOW frequency components of the image.
(ii) LPF reduces the difference between neighbouring
pixels by distributing its’ energy using averaging
technique.

Dr. Kiran TALELE 99870 30 881 [email protected] 66


6

3
(iii) LPF removes sharp transitions in the image
• Sharp transitions are due to :
(1) High frequency random Impulse Noise.
(2) High frequency Edges of an object.

. .

☆ Image Enhancement by Spatial Filtering 7


7

Eg. Consider a Digital Image F with impulse noise

F= 0 0 0
0 200 0
0 0 0

(IV) LPF reduces the difference between the


neighbouring pixels by distributing its energy
in all directions by averaging techniques
(v) The net effect of LP filtering is Image
Blurring
Dr. Kiran TALELE 99870 30 881 [email protected] 88
8

4
Eg. Digital Image with impulse noise

0 0 0
0 0 LPF
200

0 0 0

LPF reduces the difference between the


neighbouring pixels by distributing its energy in all
directions by averaging techniques

☆ Image Enhancement by Spatial Filtering 9


9

Eg-1 : Digital Image with impulse noise

A=
F= 0 1 2
LPF
7 255 3
6 5 4

Case-1 : Assume virtual Rows and Columns with Zero pixel Values

F= 0 0 0 0 0 A= A(0,0) A(0,1) A(0,2)


0 0 1 2 0

0 0 LPF A(1,0) A(1,1) A(1,2)


7 255 3
0 6 5 4 0 A(2,0) A(2,1) A(2,2)
0 0 0 0 0

10

5
(1) To find A(0,0)

A(0,0) = ( 0+0+0+0+0+1+0 +7 + 255 )/ 9


A(0,0) = 29.22
By rounding,
A(0,0) = 29

(2) To find A(0,1)

A(0,1) = ( 0 + 0 + 0 + 0 + 1 + 2 + 7 + 255 + 3 )/ 9
A(0,1) = 29.77
By rounding,

A(0,1) = 30

Dr. Kiran TALELE 99870 30 881 [email protected] 11


11
11

(3) To find A(0,2)


A(0,2) = ( 0 + 0 + 0 + 1 + 2 + 0 + 255 +3+0) /9
A(0,2) = 29
By rounding,

A(0,2) = 29

(4) To find A(1,1)


A(1,1) = ( 0 + 1 + 2 + 7 + 255 + 3 + 6 + 5 + 4 ) / 9
A(1,1) = 31.44
By rounding,
A(1,1) = 31

Dr. Kiran TALELE 99870 30 881 [email protected] 12


12
12

6
(5) To find A(1,2)
A(1,2) = ( 1 + 2 + 0 + 255 + 3 + 0 + 5 + 4 + 0 ) / 9
A(1,2) = 30
By rounding,
A(1,2) = 30

(6) To find A(2,0)


A(2,0) = ( 0 + 7 + 255 + 0 + 6 + 5 + 0 + 0 + 0) / 9
A(2,0) = 30.33
By rounding,
A(2,0) = 30

☆ Image Enhancement by Spatial Filtering 13


13

(6) To find A(2,1)


A(2,0) = ( 0 + 7 + 255 + 0 + 6 + 5 + 0 + 0 + 0) / 9
A(2,0) = 30.33
By rounding,
A(2,0) = 30

(9) To find A(2,2)


A(2,2) = ( 255 + 3 + 0 + 5 + 4 + 0 + 0 + 0 + 0) / 9
A(2,2) = 29.66
By rounding,
A(2,2) = 30

Dr. Kiran TALELE 99870 30 881 [email protected] 14


14
14

7
Derivation of LPF Mask
Consider a Digital Image F and LPF Mask w as
shown in figure below,

F = Z1 Z2 Z3 A=
LPF
Z4 Z5 Z6
Z7 Z8 Z9
w1 w2 w3
w4 w5 w6
w7 w8 w9

The response of LPF mask at (x,y) position is given by,


R = z1 w1 + z2 w2 + z3 w3 + … + z9 w9 ……(I)
Dr. Kiran TALELE 99870 30 881 [email protected] 15
15
15

Consider a Digital Image F and LPF Mask w as


shown in figure below,

F = Z1 Z2 Z3 A=
LPF
Z4 Z5 Z6 R
Z7 Z8 Z9 w =  w1 w2 w3 
 
 w4 w5 w6 
 w7 w8 w9 
 

The response of LPF mask at A(x,y) position is given by,


R = z1 w1 + z2 w2 + z3 w3 + … + z9 w9 ……(I)

☆ Image Enhancement by Spatial Filtering 16


16

8
By averaging output pixel value at (x,y) position
is given by,
R= ( z1 + z2 + z3 + … + z9 )
R= z1 + z2 + + … + z9 ) …… (II)

By equating equation (I) and (II) we get,

w= W1= W 2= W 3= w=
1 1 1
W4= W 5= W 6= 1 1 1
W7= W 8= W9 = 1 1 1

Dr. Kiran TALELE 99870 30 881 [email protected] 17


17
17

(2) Low Pass Weighted Averaging Filters


(i) In this filter, output pixel value at each
(x,y) position is obtained by averaging the
weighted neighbouring pixel values.

(ii) The Weight (i.e. Scaling factor) depends on


the position of the neighbouring pixel with
reference to the center pixel.

Dr. Kiran TALELE 99870 30 881 [email protected] 18


18
18

9
Pixel Position Weight
1 Center Pixel 4
2 Four Directional 2
Neighbour
3 Diagonal Direction 1
Neighbour

☆ Image Enhancement by Spatial Filtering 19


19

Consider a Digital Image F and filter mask w as


shown in fig below,

F= Z Z Z A=
1 2 3
Weighted
Z4 Z5 Z6 Average Filter R
Z7 Z8 Z9

The response of mask at A(x,y) position is given by,


R= [( z1 + 2 z2 + z3 )+( 2z4 + 4 z5 + 2 z6 )+ ( z7 + 2 z8 + z9 ) ]

☆ Image Enhancement by Spatial Filtering 20


20

10
(3) Trimmed Averaging Filter
A non-linear smoothing filter.

This filter deals well with images containing spiky


noise, but it is less effective at attenuating random
noise

☆ Image Enhancement by Spatial Filtering 21


21

Trimmed Mean Filter ALGORITHM :

1. Place a window over element;


2. Pick up elements;
3. Order elements;
4.Discard elements at the beginning and at the end of the got
5.ordered set;
5.Take an average — sum up the remaining elements and
divide the sum by their number.

Since the filter applies a mean to the untrimmed data, it


is not edge preserving

Dr. Kiran TALELE 22


22

11
(4) Alpha (α)-Trimmed Averaging Filter
A non-linear smoothing filter.

For ex. Consider below window size

F = 20 20 18 A=
21 19 12 A(x,y)
19 22 10

The ordered list is :


F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}

☆ Image Enhancement by Spatial Filtering 23


23

To find A(x,y)
For different values of α, the output is as follows:

Case-1 : When α = 0
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =

Case-2 : When α = 1

F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}


A(x,y) =

Dr. Kiran TALELE 24


24

12
Case-3 : When α = 2
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =
Case-4 : When α = 3
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =

Case-5 : When α = 4
F = { 8, 10, 12, 19, 19, 20, 20, 21, 22}
A(x,y) =

☆ Image Enhancement by Spatial Filtering 25


25

This filter is a combination of mean filter and median


filter.

This is an algorithmic approach that tries to combine


properties of the mean filter with properties of the
median filter.

Dr. Kiran TALELE 26


26

13
(5) Geometric Mean Filter
The geometric mean filter is an image filtering process
meant to smooth and reduce noise of an image.

It is based on the mathematic geometric mean.

The output image G(x,y) of a geometric mean is


given by

☆ Image Enhancement by Spatial Filtering 27


27

Eg. Consider a digital subimage F

F= 5 16 22 A=
Geometric
6 3 18 Mean A(x,y)
Filter
12 3 15

The output pixel value at A(x,y) position is given by,

A(x,y) = (5 * 16 * 22 * 6 * 3 * 18 * 12 * 3 * 15)^(1/9)

A(x,y) = 8.77

Dr. Kiran TALELE 28


28

14
[II] Smoothing Non-Linear Filters
[ also called as ordered statistic filters]

(1) Median Filter


(i) Medial filter is a Non-Linear ordered statistic filter.
(ii) Output pixel value at (x,y) position is obtained by
selecting the median of neighbourhood of input pixel
value.

☆ Image Enhancement by Spatial Filtering 29


29

* Median Filter ALGORITHM


(I) Arrange the pixels in the window either in Increasing
order OR in Decreasing order.
(II) Select the middle value
If number of pixels in the window are even,
Then find average of the middle two values.

(III) Replace the input pixel value by the selected median


value in the output image.

Dr. Kiran TALELE 30


30

15
Eg. Consider a Digital Image F

F = 41 200 60 A=
52 45 72 Median A(x,y)
Filter
10 58 81

1. Arrange All the pixel values in asceding order

58

2. Select the middle value


A(x,y) = 58

☆ Image Enhancement by Spatial Filtering 31


31

Ex of Digital Image with Salt and Pepper Noise :

F = 41 200 60 Salt Noise Value = (White)


52 45 42 Pepper Noise Value = (Black)
0 58 51

Most of the pixels in the image are in the range


[ 40 to 60 ]

There are two extreme values in the image :


i.e. 200 (Salt Noise) and 0 (Pepper Noise)

Dr. Kiran TALELE 32


32

16
To remove noisy pixels, assume virtual rows and
columns with repeated border pixel values

A=
41 41 200 60 60

F= 41 41 200 60 60 Median
Filter
52 52 45 42 42
0 0 58 51 51
0 0 58 51 51

Dr. Kiran TALELE 99870 30 881 [email protected] 33


33

▪ Median Filter forces the points


F= 41 200 60 with distinct gray levels to be
more like their neighbours
52 45 42
0 58 51 ▪ When all the pixel values are
arranged in order, distinct
A = 45 52 60 values occupy extreme
positions and Median filter
45 51 51
selects median i.e. middle
45 51 51 vales of ordered pixel values.
▪ Therefore, noisy pixel values
are eliminated median filter

Dr. Kiran TALELE 99870 30 881 [email protected] 34


34

17
F= 41 200 60 ▪ Eliminated noisy pixel values
are replaced by one of the
52 45 42
neighbouring pixel values.
0 58 51

A = 45 52 60 ▪ Therefore, Median Filter is the


most suitable to remove Salt
45 51 51
and Pepper Noise in the
45 51 51 image.


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 35
35

(2) Max Filter


(i) Max filter is a Non-Linear ordered statistic filter.
(ii) Output pixel value at (x,y) position is obtained by
selecting the Maximum of neighbourhood of input
pixel value.
(3) Min Filter

(i) Min filter is a Non-Linear ordered statistic filter.


(ii) Output pixel value at (x,y) position is obtained by
selecting the Minimum of neighbourhood of input
pixel value.

Dr. Kiran TALELE 99870 30 881 [email protected] 36


36

18
Eg.

F= 41 200 60 A=
52 45 42
Max
200
Filter
0 58 51

F= 41 200 60 A=
52 45 42
Min
0
Filter
0 58 51


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 37
37

Sharpening Derivative Filters


Concept :

Smoothing
SUM Integration
Filter
Ex. LPF
Sharpening
Filter Difference Differentiation
Ex. HPF


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 38
38

19
[ III ] Sharpening First Order Derivative filters
[also called as Gradient Filters]
Eg: Robert, Prewit, Sobel and Fri-chen filters

▪ Method of differentiation is Gradient


▪ The Gradient of F at (x,y) position is defined as,

Dr. Kiran TALELE 99870 30 881 [email protected] 39


39

Where,


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 40
40

20
y-1 y y+1
F=
x-1

x+1

Dr. Kiran TALELE 99870 30 881 [email protected] 41


41

y
1. Robert Filter F=
( 1st Order Derivative Sharpening filter )
x
▪ To find Gx

▪ To find Gy
-
-

-1 0
1 0 -1 1
0 0


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 42
42

21
y
2. Prewit Filter z1 z2 z3
( 1st Order Derivative - Sharpening filter ) x z4 z5 z6
z7 z8 z9
▪ To find Gx ▪ To find Gy
Gx= (z7–z1)+ (z8–z2) + (z9–z3) Gx= (z3–z1)+(z6–z4)+ (z9–z7)

Dr. Kiran TALELE 99870 30 881 [email protected] 43


43

y
3. Sobel Filter z1 z2 z3
( 1st Order Derivative - Sharpening filter ) x z4 z5 z6
z7 z8 z9
▪ To find Gx ▪ To find Gy
Gx= (z7–z1) +2 (z8–z2) + (z9–z3) Gy= (z3–z1)+ 2 (z6–z4) + (z9–z7)


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 44
44

22
y
4. Fri-Chen Filter z1 z2 z3
( 1st Order Derivative - Sharpening filter ) x z4 z5 z6
z7 z8 z9
▪ To find Gx ▪ To find Gy
Gx= (z7–z1) + (z8–z2)+(z9–z3) Gy= (z3–z1)+ (z6–z4)+ (z9–z7)

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

Dr. Kiran TALELE 99870 30 881 [email protected] 45


45

1. The Magnitude of Gradient at (x,y) is given by,

2. Orientation at (x,y) is given by,

α=


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 46
46

23
Example-1 :

F= 41 200 60 Prewit A=
52 45 42 Gradient R
0 58 51 Filter

Prewit Vertical Mask is given by, (i) To find Gx


Gx = (-41) + (-142) + (-9)
-1 -1 -1
Gx = -192
0 0 0
1 1 1


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 47
47

Similarly,

F= 41 200 60 Prewit A=
52 45 42 Gradient R
0 58 51 Filter

Prewit Horizontal Mask is given by, (ii) To find Gy


Gy = (19) + (-10) + (51)
-1 0 1
Gx = 60
-1 0 1
-1 0 1

Dr. Kiran TALELE 99870 30 881 [email protected] 48


48

24
Example...

F= 41 200 60 Prewit A=
52 45 42 Gradient R
0 58 51 Filter

(iii) To find R

( 192 ) + ( 60 )

( 252 )

Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 49
49

[IV] Second Order Derivative filters


Eg. Laplacian Filter, HPF and High Boost Filter

(2) Laplacian Filter


The Laplacian filter is Second Order Derivative filter

The Laplacian of Digital image f at (x,y) position is


given by,

Dr. Kiran TALELE 99870 30 881 [email protected] 50


50

25
y-1 y y+1
(i) Find G2x x-1 f(x-1,y)

x f(x,y-1) f(x,y) f(x,y+1)

Gx = f(x+1,y) - f(x,y) x+1 f(x+1,y)

G2x = [ f(x+1,y) - f(x,y)] – [ f(x,y) - f(x-1,y )]

G2x = f(x+1,y) – 2 f(x,y) + f(x-1,y )

G2x = 0 1 0 G2x =

0 -2 0

0 1 0 Scale by (-1)


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 51
51

y-1 y y+1
(i) Find G2y x-1 f(x-1,y)

x f(x,y-1) f(x,y) f(x,y+1)


Gy = f(x, y+1) - f(x,y)
x+1 f(x+1,y)

G2y = [ f(x, y+1) - f(x,y)] – [ f(x,y) - f(x, y-1 )]

G2y = f(x, y+1) – 2 f(x,y) + f(x, y-1)

G 2y = 0 0 0 G2y =

1 -2 1

0 0 0 Scale by (-1)

Dr. Kiran TALELE 99870 30 881 [email protected] 52


52

26
y-1 y y+1
(iii) Find x-1 f(x-1,y)

x f(x,y-1) f(x,y) f(x,y+1)

x+1 f(x+1,y)

=
+

=
Laplacian 4 directional
Mask


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 53
53

(iv) Find

= +
( 4 Directional) ( Diagonal Directional)

= 0 -1 0 -1 0 -1
+
-1 4 -1 0 4 0
0 -1 0 -1 0 -1

= -1 -1 -1
Laplacian 8 directional
-1 8 -1
Mask
-1 -1 -1

Dr. Kiran TALELE 99870 30 881 [email protected] 54


54

27
(2) High Pass Filter
(i) HPF attenuates LOW frequency Components and
allows to pass HIGH frequency components of the
image.
(ii) HPF image can be obtained by subtracting LPF image
from the original image.
(iii) HPF Mask is given by,
w=
-1 -1 -1
-1 8 -1
-1 -1 -1


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 55
55

Eg. Consider a Digital Image F as given below

10 10
100
200 100
200 0 30 30 0
H PF
10 10 200
100 100
200 0 30 30 0
10 10 200
100 100
200 0 30 30 0
-1 -1 -1
W= -1 8 -1
-1 -1 -1

10 10 10 100 100 100

10 10 10 100 100 100 0 30 30 0


10 10 10 100 100 100 0 30 30 0
10 10 10 100 100 100 0 30 30 0
10 10 10 100 100 100

Dr. Kiran TALELE 99870 30 881 [email protected] 56


56

28
Derivation of HPF Mask
Consider a Digital Image F and HPF Mask w as
shown in figure below,

Z1 Z2 Z3
LPF A(x,y)
Z4 Z5 Z6
Z7 Z8 Z9
w =  w1 w2 w3 
 
 w4 w5 w6 
 w7 w8 w9 
 
The response of HPF mask at A(x,y) position is given by,
A(x,y) = z1 w1 + z2 w2 + z3 w3 + …+ z9 w9 ……(I)
Dr. Kiran TALELE 99870 30 881 [email protected] 57
57

Consider a Digital Image F and LPF Mask w as


shown in figure below,

Z1 Z2 Z3
LPF
Z4 Z5 Z6 B(x,y)

Z7 Z8 Z9 w = 1 1 1
1 1 1
1 1 1

The response of LPF mask at B(x,y) position is given by,

B(x,y) = z1 + z2 + + … + z9 …… (II)


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 58
58

29
Now, Original Image = LPF Image + HPF Image

HPF Image = Original Image - LPF Image

= Z1 Z2 Z3 -
A(x,y) B(x,y)
Z4 Z5 Z6
Z7 Z8 Z9

At (x,y) position,

A(x,y) = Z5 - B(x,y)

Dr. Kiran TALELE 99870 30 881 [email protected] 59


59

Now, A(x,y) = Z5 - B(x,y)

Where, B(x,y) = z1 + + z2 + + … + z9

A(x,y) = Z5 – ( z1 z1 + -- z2 + + + + z9 )

= Z5 - z1 - z2 - z3 - z4 - Z5 … z9 )

A(x,y) = - z1 - z2 - z3 - z4 + Z5 + z9..) ----(III)


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 60
60

30
By equating equation (I) and (III) we get,

w= W1= W 2= W 3= w=

W4= W 5= W 6=

W7= W 8= W9 =

Dr. Kiran TALELE 99870 30 881 [email protected] 61


61

(3) High Boost Filter

High Boost Filter (HBF) Image is obtained by adding HPF


image with the original Image.

HBF Image = Original Image + HPF Image

= Z1 Z2 Z3 +
A(x,y) B(x,y)
Z4 Z5 Z6
Z7 Z8 Z9

At (x,y) position,

A(x,y) = Z5 + B(x,y)


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 62
62

31
Now, A(x,y) = Z5 + B(x,y)

Where, B(x,y) = - z1 - z2 - z3 - z4 + z5 - z9

By Substituting,

A(x,y) = Z5 + ( - z1 - z2 - z3 - z4 + Z5 - z9)

A(x,y) = - z1 - z2 - z3 - z4 + Z5 … - z9

Let A(x,y) = z1 w1 + z2 w2 + z3 w3 + … + z9 w9

Dr. Kiran TALELE 99870 30 881 [email protected] 63


63

By equating, HBF Mask is then given by,

w= W1= W 2= W 3= w=

W4= W 5= W 6=

W7= W 8= W9 =


Dr.Image
Kiran Enhancement
TALELE by
99870
Spatial
30Filtering
881 [email protected] 64
64
64

32

You might also like