noise filtering & edge detection jeremy wyatt. filtering last time we saw that we could detect...
Post on 21-Dec-2015
216 views
TRANSCRIPT
Noise Filtering & Edge Detection
Jeremy Wyatt
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Effect of mean filtering
Original 3x3 filter 5x5 filter
Horizontal Sobel operator
Abs(Gx)
Threshold=30
5x5 Mean Filter
Horizontal Sobel operator
Abs(Gx)
Threshold=30
Effect of Gaussian filtering
Original 5x5 filter Horizontal Sobel Operator
Abs(Gx)Threshold = 30
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
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
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
Reading
RC Jain, Chapter 4