Title: Contour Extraction
1Contour Extraction
Lecture 10
2Canny Edge Detection
- Steps
- Canny enhancer
- Image smoothing by Gaussian filter
- Computing the image gradient
- Non-maximum suppression
- Thin multi-pixel wide ridges down to single
pixel width - Linking and thresholding
- Low, high edge-strength thresholds
- Accept all edges over low threshold that are
connected to edge over high threshold
3CANNY_ENHANCER
- The input is image I
G is a zero mean Gaussian
filter (std ?) - J I G (smoothing)
- For each pixel (i,j) (edge enhancement)
- Compute the image gradient
- ?J(i,j) (Jx(i,j),Jy(i,j))
- Estimate edge strength
- Mag(i,j) (Jx2(i,j) Jy2(i,j))1/2
- Estimate edge orientation
- Dir(i,j) arctan(Jy(i,j)/Jx(i,j))
- The output are images Mag and Dir
4How do we detect edges?
- Mag has large values at edges
- Find local maxima
5- but it also may have wide ridges around the
local maxima (large values around the edges)
6Graphical Interpretation
x
x
7Non-maximum suppression Select the single
maximum point across the width of an edge.
8NONMAX_SUPRESSION (Mag,Dir)
- Consider 4 directions Del (1,0),(1,1),(0,1),(
-1,1) -
Del- (-1,0),(-1,-1),(0,-1),(1,1) - For each pixel (i,j) do
- Find the direction of gradient (normal to the
edge) d
(Dir(i,j)?/8) mod ?/4 - If Mag(i,j) is smaller than at least one of its
neigh. along d then IN(i,j)0, otherwise,
IN(i,j) Mag(i,j) - If Mag(i,j)ltMag((i,j)Del(d)) then IN(i,j)0
- Else If Mag(i,j)ltMag((i,j)Del-(d)) then
IN(i,j)0 - Else INMag(i,j)
- The output is the thinned edge image IN
9Thresholding
- Edges are found by thresholding the output of
NONMAX_SUPRESSION - If the threshold is too high
- Very few (none) edges
- High MISDETECTIONS, many gaps
- If the threshold is too low
- Too many (all pixels) edges
- High FALSE POSITIVES, many extra edges
10Edge Hysteresis (Lag)
- Idea Maintain two thresholds thigh and tlow
- Use thigh to find strong edges to start edge
chain - Use tlow to find weak edges which continue edge
chain - Typical ratio of thresholds is roughly
- thigh / tlow 2
11HYSTERESIS_THRESH(IN,Dir,Tlow,Thigh)Edge Linking
- For all pixels in IN scanning in a fixed order
- Locate the next unvisited pixel s.t.
IN(i,j)gtThigh - Starting from IN(i,j), follow the chains of
connected local maxima, in both directions
perpendicular to the edge normal, as long as
INgtTlow. - Mark all visited points, and save the location of
the contour points. - Output a set of lists describing the contours.
12Canny Edge Detection (Example)
Strong connected weak edges
Original image
Strong edges only
Weak edges
courtesy of G. Loy
13Effect of threshold
original
? 1
? 1
Thigh 255 Tlow 220
Thigh 255 Tlow 1
14Effect of threshold and of ? (Gaussian kernel
size)
original
? 1
? 2
Thigh 120 Tlow 1
Thigh 120 Tlow 1
15?? ????
? 0.002
16Salt Pepper noise
17Edge Linking
- The next step is to try to collect these pixels
together into a set of edges lines, contours. - The practical problem may be much more difficult
than the idealized case - Small pieces of edges may be missing
- Small edge segments may appear to be present due
to noise where there is no real edge, etc.
18In general, edge linking methods can be
classified into two categories Local Edge
Linkers -- where edge points are grouped to form
edges by considering each point's
relationship to any neighbouring edge points.
Global Edge Linkers -- where all edge points
in the image plane are considered at the same
time and sets of edge points are sought according
to some similarity constraint, such as points
which share the same edge equation.
19- Local Edge Linking Methods
- Most edge detectors yield information about the
magnitude of the gradient at an edge point and,
more importantly, the direction of the edge in
the locality of the point. - This is obviously useful when deciding which edge
points to link together since edge points in a
neighbourhood which have similar gradients
directions are likely to lie on the same edge.
20- Local edge linking methods usually start at some
arbitrary edge point and consider points in a
local neighbourhood for similarity of edge
direction. - If the points satisfy the similarity constraint
then the points are added to the current edge
set. - If the points do not satisfy the constraint then
we conclude we are at the end of the edge, and so
the process stops. - A new starting edge point is found which does not
belong to any edge set found so far, and the
process is repeated. - An advantage of such methods is that they can
readily be used to find arbitrary curves.
21- Other methods have posed the edge linking problem
as - A graph or tree search problem
Linkage rule
?Mag(pi) ? max
22- Other methods have posed the edge linking problem
as - A graph or tree search problem
6
5
7
6
5
2
3
4
3
3
2
23- Other methods have posed the edge linking problem
as - A graph or tree search problem
- Dynamic programming problem -- where functions
measuring the error in the fitting of an edge to
a set of points are minimized to find the best
fitting edges in the image -
- Many other edge linking techniques exist