Edge Detection

advertisement
Edges and Contours– Chapter 7
Visual perception
• We don’t need to see all the color detail to recognize the scene
content of an image
• That is, some data provides critical information for recognition,
other data provides information that just makes things look
“good”
Visual perception
• Sometimes we see things that are not
really there!!!
Kanizsa Triangle (and variants)
Edges
• Edges (single points) and contours (chains of
edges) play a dominant role in (various)
biological vision systems
– Edges are spatial positions in the image where the
intensity changes along some orientation
(direction)
– The larger the change in intensity, the stronger the
edge
– Basis of edge detection is the first derivative of the
image intensity “function”
First derivative – continuous f(x)
• Slope of the line at a point tangent to
the function
df
f ' ( x) 
( x)
dx
First derivative – discrete f(u)
• Slope of the line joining two adjacent (to the selected
point) point
f (u  1)  f (u  1)
f ' (u ) 
2
u-1
u
u+1
Discrete edge detection
• Formulated as two partial derivatives
– Horizontal gradients yield vertical edges
I
(u , v )
u
– Vertical gradients yield horizontal edges
I
(u , v )
v
– Upon detection we can learn the magnitude
(strength) and orientation of the edge
• More in a minute…
NOTE
• In the following images, only the
positive magnitude edges are shown
• This is an artifact of ImageJ
Process->Filters->Convolve…
command
• Implemented as an edge operator, the
code would have to compensate for this
Detecting edges – sharp image
Image
Vertical
Edges
 0.5
0.0 0.5
Horizontal
Edges
  0 .5 
 0 .0 


 0.5 
Detecting edges – blurry image
Image
Vertical
Edges
 0.5
0.0 0.5
Horizontal
Edges
  0 .5 
 0 .0 


 0.5 
The problem…
• Localized (small neighborhood)
detectors are susceptible to noise
The solution
• Extend the neighborhood covered by
the filter
– Make the filter 2 dimensional
• Perform a smoothing step prior to the
derivative
– Since the operators are linear filters, we
can combine the smoothing and derivative
operations into a single convolution
Edge operator
• The following edge operators produce
two results
– A “magnitude” edge map (image)
E (u, v) 
D x(u,v)  D y (u,v)
2
2
– An “orientation” edge map (image)
(u, v)  tan
1
 D y (u, v) 




(
u
,
v
)
D
x


Prewitt operator
• 3x3 neighborhood
 1 0 1
P
 1 0 1

Hx 

 1 0 1
 1  1  1
P
0 0 0

Hy 

 1 1 1 
• Equivalent to averaging followed by derivative
– Note that these are convolutions, not matrix multiplications
1
P
1   1 0 1

Hy  
1
 1
P
0



1
1
1

Hy
 
 1 
Prewitt – sharp image
Prewitt – blurry image
Prewitt – noisy image
• Clearly this is not a good solution…what went wrong?
– The smoothing just smeared out the noise
• How could you fix it?
– Perform non-linear noise removal first
Prewitt magnitude and direction
Prewitt magnitude and direction
Sobel operator
• 3x3 neighborhood
  1 0 1
P
 2 0 2

Hx 

  1 0 1 
 1  2  1
P
0


0
0
Hy 

 1
2
1 
• Equivalent to averaging followed by derivative
– Note that these are convolutions, not matrix multiplications
1 
P
2   1 0 1

Hy  
1 
 1
P
0



1
2
1

Hy
 
 1 
– Same as Prewitt but the center row/column is weighted
heavier
Sobel – sharp image
Sobel – blurry image
Sobel – noisy image
• Clearly this is not a good solution…what went wrong?
– The smoothing just smeared out the noise
• How could you fix it?
– Perform non-linear noise removal first
Sobel magnitude and direction
Sobel magnitude and direction
Sobel magnitude and direction
• Still not good…how could we fix this now?
• Using the information of the direction (lots of randomly oriented,
non-homogeneous directions) can help to eliminate edged due
to noise
– This is a “higher level” (intelligent) function
Roberts operator
• Looks for diagonal gradients rather than
horizontal/vertical
H
R
1
 0 1


 1 0
H
R
2
 1 0


 0 1
• Everything else is similar to Prewitt and
Sobel operators
Roberts magnitude and direction
Roberts magnitude and direction
Roberts magnitude and direction
Compass operators
• An alternative to computing edge
orientation as an estimate derived from
two oriented filters (horizontal and
vertical)
• Compass operators employ multiple
oriented filters
• To most famous are
– Kirsch
– Nevatia-Babu
Kirsch Filter
• Eight 3x3 kernel
– Theoretically must perform eight convolutions
– Realistically, only compute four convolutions, the other four
are merely sign changes
• The kernel that produces the maximum response is
deemed the winner
– Choose its magnitude
– Choose its direction
Kirsch filter kernels
1 0 1
1 0
1
2 0 2
1 0 1
2 0 2
1 0 1
Vertical edges
 2 1 0
2
1
0
1 0 1
0 1  2
0
1
1
2
1
0
L-R diagonal edges
1  2 1
1
0
1
0
0
0
1  2 1
0
2
0
1
0 1  2
1
2
0
1
1
0
2
0
1
1
Horizontal edges
2
1 0 1
 2 1 0
R-L diagonal edges
Kirsch filter
Nevatia-Babu Filter
• Twelve 5x5 kernel
– Theoretically must perform twelve convolutions
– Increments of approximately 30°
– Realistically, only compute six convolutions, the
other six are merely sign changes
• The kernel that produces the maximum
response is deemed the winner
– Choose its magnitude
– Choose its direction
Nevatia-Babu filter
Download