עיבוד תמונה- הרצאות - Canny Edge Detection
עיבוד תמונה- הרצאות - Canny Edge Detection
עיבוד תמונה- הרצאות - Canny Edge Detection
=
Gradient
operator
image
Thresholding
edge
map
x(m,n)
g(m,n)
e(m,n)
>
=
otherwise
T n m g
n m e
0
| ) , ( | 1
) , (
Gradient:
edge pixel threshold
non edge pixel
Gradient Operators
Gradient-Based Methods
(
0 1
1 0
(
1 0
0 1
(
(
(
1 0 1
1 0 1
1 0 1
(
(
(
1 1 1
0 0 0
1 1 1
(
(
(
1 0 1
2 0 2
1 0 1
(
(
(
1 2 1
0 0 0
1 2 1
Robert:
Prewitt:
Sobel:
g
1
g
2
) , ( ) , (
) , (
2
2
2
1
n m g n m g
n m g
+
=
(
=
) , (
) , (
) , (
2
1
n m g
n m g
n m g
Local gradient vector:
Gradient magnitude:
) , ( ) , (
2 1
n m g n m g +
Approximation:
Generalization: Compass Operator
Gradient-Based Methods
maximal magnitude:
Thresholding
edge image
(
(
(
1 0 1
1 0 1
1 0 1
(
(
(
1 1 1
0 0 0
1 1 1
(
(
(
1 1 1
0 0 0
1 1 1
(
(
(
1 0 1
1 0 1
1 0 1
(
(
(
1 1 0
1 0 1
0 1 1
(
(
(
1 1 0
1 0 1
0 1 1
(
(
(
0 1 1
1 0 1
1 1 0
(
(
(
0 1 1
1 0 1
1 1 0
|} ) , ( {| max ) , ( n m g n m q
k
k
=
Sobel Edge Detector
I
dx
d
I
dy
d
I
Sobel Edge Detector
I
2
2
|
|
\
|
+
|
\
|
= I
dy
d
I
dx
d
100 = Threshold
Gradient-Based Methods
original image
) , ( ) , (
2 1
n m g n m g + ) , (
2
n m g
) , (
1
n m g
From [Gonzalez & Woods]
Use to estimate the gradient
magnitude, and use T = 5 as the threshold for edge detection
Use to estimate the gradient
magnitude, and use T = 20 as the threshold for edge detection
Use Sobel gradient operator to find its edges
Examples
) , ( ) , ( ) , (
2
2
2
1
n m g n m g n m g + =
) , ( ) , ( ) , (
2 1
n m g n m g n m g + =
A 9x9 original
image is given by
9
2
2
2
2
2
3
2
2
2
2
2
2 2 2
9
9
9
2
2
9 9 9 9 9
9 8 9 9 9
9 9 9 9 9
9 9 9 9 9
7 9 9 9 9
2
2
4
2
2
2
1 2 2
2 2 2
2
2
2
2 9 9 9 9 2
9 9 9 9 2
9 9 9 2 2
9 9 2 2 2
Use Sobel gradient operator
Examples
original
image
g
1
g
2
= ) , ( n m g
) , (
1
n m g
) , (
2
n m g
) , ( n m e
edge map
thresholding
T = 20
(
(
(
1 0 1
2 0 2
1 0 1
(
(
(
1 2 1
0 0 0
1 2 1
) , ( ) , (
2 1
n m g n m g +
-20
-21
-28
-26
-21 0
0
-7
-28
0 2 0
0 1 0
4 0 -7
0
2
4
-1
-7 2
-21
-7
-28 2 0 -21
0 -7 -28
-7 -21 -21
-2
-8
0
1
0
0
-7 -27 -21 2 0 0 -1
-6 -12
-7
-1
0
-9
0 0
-6
-14
-15
-7
0 0 0 0
2 1 0 -7
-2 0 0 -7
0 0 -7 -14
0
-5
0
-4
2 4
0
-1
-7 2 0 -7 -14
0 -7 -14 -7
-7 -21 -21 -7
40 26
40
16
28
42
14 4
0
14
28
42
0 2 0
2 2 0
4 0 0
4 0 28
2 6
0 4
14
28 0 14 42
14 42 42
14
2
2
4
6
0
0 28 42 4 0 14 0
1 1
1
0
1
1
0 0
0
0
1
1
0 0 0
0 0 0
0 0 0
0 0 1
0 0
0 0
0
1 0 0 1
0 1 1
0
0
0
0
0
0
0 1 1 0 0 0 0
Note: 7x7 images (because of boundary problems)
Gradient-Based Methods:
Problems with standard gradient edge detectors
noise-sensitive;
thick edge;
broken edge contour;
hard to pick threshold
Canny Edge Detector
image
smoothing with Gaussian
differentiating along x and y axis
finds peaks in gradient image
thinning (locating edge strings)
edge map
thresholding
Canny
Edge
Detector
Smoothing
Reduce image noise by smoothing with
a Gaussian
Edge orientation
Would like gradients in all directions
Approximate:
Compute smoothed derivatives in x,y
directions
Edge strength
Edge normal
Canny Edge Detection
Compute edge strength and orientation at
all pixels
Non-max suppression
Reduce thick edge strength responses around
true edges
Link and threshold using hysteresis
Simple method of contour completion
Non-Max Supression
Suppress non-maxima pixels in the edges
in obtained above to thin the edge ridges
To do so, check to see whether each non-
zero is greater than its two neighbors
along the gradient direction . If so, keep
unchanged, otherwise, set it to 0
Non-maximum suppression
Check if pixel is local maximum along
gradient direction
requires checking interpolated pixels p and r
Thresholding Dilemma
Define a threshold in the magnitude-image
Assume high magnitudes originate from
objects
Dilemma:
Too high threshold:
Remove noise
Remove small edges
Too low threshold:
Keep noise
Keep small edges
Edge Hysteresis
Hysteresis: A lag or momentum factor
Idea: Maintain two thresholds k
high
and k
low
Use k
high
to find strong edges to start edge
chain
Use k
low
to find weak edges which continue
edge chain
Typical ratio of thresholds is roughly
k
high
/ k
low
= 2
Hysteresis Thresholding
If the gradient at a pixel is above High, declare
it an edge pixel
If the gradient at a pixel is below Low, declare it
a non-edge-pixel
If the gradient at a pixel is between Low and
High then declare it an edge pixel if and only if
it is connected to an edge pixel directly or via
pixels between Low and High
original image horizontally filtered vertically filtered
gradient magnitude after thresholding after thinning
Gradient-Based Methods: Canny Edge Detector
Effect of (Gaussian kernel size)
Canny with Canny with original
The choice of depends on desired behavior
large detects large scale edges
small detects fine features
Problem?
Texture
Canny edge detection responds all over
textured regions