+ All Categories
Home > Documents > Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges...

Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges...

Date post: 21-Dec-2015
Category:
View: 213 times
Download: 0 times
Share this document with a friend
Popular Tags:
27
Noise Filtering & Edge Detection Jeremy Wyatt
Transcript
Page 1: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Noise Filtering & Edge Detection

Jeremy Wyatt

Page 2: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Filtering

Last time we saw that we could detect edges by calculating the intensity change (gradient) across the image

We saw that we could implement this using the idea of filtering

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

Page 3: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i

j

NB We count from the upper left,and in MATLAB we start at 1

Page 4: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

0

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 5: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

0

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 6: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

1

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 7: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

1

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 8: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

1

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 9: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

5

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 10: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

5

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 11: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

5

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 12: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=2

Page 13: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=3

Page 14: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14 4

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=4

Page 15: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14 4 3

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=2

j=5

Page 16: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14 4 3

10

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=3

j=2

Page 17: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14 4 3

10 16

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=3

j=3

Page 18: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14 4 3

10 16 3

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=3

j=4

Page 19: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Linear Filtering: the algorithm

for i=2:image_height-1

for j=2:image_width-1

end

end

0 1 1 3 4 5

0 0 2 3 3 4

0 0 4 6 3 5

0 0 0 4 4 3

0 0 0 3 5 2

0 0 0 0 5 5

0 0 0 0 4 3

-1 0 1

-2 0 2

-1 0 1

9 14 4 3

10 16 4 -2

i+y

j+x

1 1

1 1

( , ) ( 2, 2)out iny x

i y j x y x

A (i, j) A M

y+2

x+2

i=3

j=5

Page 20: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Noise filtering

We can use convolution to remove noise as we mentioned, e.g. mean filter

This is a linear filter The most widely used is Gaussian filtering

1

9

1

9

1

9

1

9

1

9

1

9

1

9

1

9

1

9

0 .01 .02 .01 0

.01 .06 .11 .06 .01

.02 .11 .16 .11 .02

.01 .06 .11 .06 .01

0 .01 .02 .01 0

Page 21: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Effect of mean filtering

Original 3x3 filter 5x5 filter

Page 22: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Horizontal Sobel operator

Abs(Gx)

Threshold=30

5x5 Mean Filter

Horizontal Sobel operator

Abs(Gx)

Threshold=30

Page 23: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Effect of Gaussian filtering

Original 5x5 filter Horizontal Sobel Operator

Abs(Gx)Threshold = 30

Page 24: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Sequenced filtersWe can replace a 2d Gaussian filter with 2, 1d Gaussian filters in

sequence

0.003 .0133 .0219 .0133 0.003

.0133 .0596 .0983 .0596 .0133

.0219 .0983 .1621 .0983 .0219

.0133 .0596 .0983 .0596 .0133

0.003 .0133 .0219 .0133 0.003

.0545 .2442 .4026 .2442 .0545

.0545

.2442

.4026

.2442

.0545

Page 25: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Gaussian edge detection

We can take the first derivative of the masks and then convolve with those

Then we can combine the resulting images using the formula for magnitude

However when thresholded we can see that this loses edge information

How can we keep this?

.1897 .1741 0 -.1741 -.1897

2 2( ) x yM G G G

Page 26: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Second order operators Thresholding the first derivative of

the smoothed signal thickens the edges and also we lose some useful edges

One solution is therefore to take the second derivative instead

A basic second order mask is the Laplacian

0 1 0

1 -4 1

0 1 0

Page 27: Noise Filtering & Edge Detection Jeremy Wyatt. Filtering Last time we saw that we could detect edges by calculating the intensity change (gradient) across.

Reading

RC Jain, Chapter 4


Recommended