Noise Filtering Edge Detection Jeremy Wyatt Filtering n

  • Slides: 27
Download presentation
Noise Filtering & Edge Detection Jeremy Wyatt

Noise Filtering & Edge Detection Jeremy Wyatt

Filtering n Last time we saw that we could detect edges by calculating the

Filtering n Last time we saw that we could detect edges by calculating the intensity change (gradient) across the image n We saw that we could implement this using the idea of filtering -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3

Linear filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y NB We count from the upper left, and in MATLAB we start at 1 j i

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 0

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 0

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 1

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 1

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 1

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 5

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 5

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 5

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 9

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=3 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 9 14

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=4 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 9 14 4

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=5 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=2 9 14 4 3

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=2 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y 9 i=3 10 14 4 3

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=3 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=3 9 14 10 16 4 3

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=4 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=3 9 14 4 10 16 3 3

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2

Linear Filtering: the algorithm for i=2: image_height-1 for j=2: image_width-1 end y+2 j+x x+2 j=5 -1 0 1 1 3 4 5 -2 0 0 2 3 3 4 -1 0 0 4 6 3 5 0 0 0 4 4 3 0 0 0 3 5 2 0 0 5 5 0 0 4 3 i+y i=3 9 14 4 3 10 16 4 -2

Noise filtering n We can use convolution to remove noise as we mentioned, e.

Noise filtering n We can use convolution to remove noise as we mentioned, e. g. mean filter This is a linear filter n The most widely used is Gaussian filtering n 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

Effect of mean filtering Original 3 x 3 filter 5 x 5 filter

Effect of mean filtering Original 3 x 3 filter 5 x 5 filter

Horizontal Sobel operator Abs(Gx) Threshold=30 5 x 5 Mean Filter Horizontal Sobel operator Abs(Gx)

Horizontal Sobel operator Abs(Gx) Threshold=30 5 x 5 Mean Filter Horizontal Sobel operator Abs(Gx) Threshold=30

Effect of Gaussian filtering Original 5 x 5 filter Horizontal Sobel Operator Abs(Gx) Threshold

Effect of Gaussian filtering Original 5 x 5 filter Horizontal Sobel Operator Abs(Gx) Threshold = 30

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

Sequenced filters We can replace a 2 d Gaussian filter with 2, 1 d Gaussian filters in sequence 0. 003 . 0133 . 0219 . 0133 0. 003 . 0133 . 0596 . 0983 . 0596 . 0133 . 0219 . 0983 . 1621 . 0983 . 0219 . 0545 . 2442 . 4026 . 0545. 0133 . 0596 . 0983 . 0596 . 0133. 2442 0. 003 . 0133 . 0219 . 0133 0. 003. 4026 . 2442 . 0545

Gaussian edge detection n We can take the first derivative of the masks and

Gaussian edge detection n We can take the first derivative of the masks and then convolve with those. 1897 . 1741 0 . 1741 . 1897 n Then we can combine the resulting images using the formula for magnitude n However when thresholded we can see that this loses edge information n How can we keep this?

Second order operators n Thresholding the first derivative of the smoothed signal thickens the

Second order operators n Thresholding the first derivative of the smoothed signal thickens the edges and also we lose some useful edges n One solution is therefore to take the second derivative instead n A basic second order mask is the Laplacian 0 1 -4 1 0

Reading n RC Jain, Chapter 4

Reading n RC Jain, Chapter 4