Hough2 PDF
Hough2 PDF
INF 4300 2
An image with linear structures
• Borders between the regions are
straight lines.
• These lines separate regions
with different grey levels.
• Edge detection is often used as
preprocessing to Hough
transform.
INF 4300 3
INF 4300 4
Hough transform – the input
Hough-transform
INF 4300 5
• …which
which is a vector quantity given by:
INF 4300 6
Repetition – Edge magnitude
• The gradient is a measure of how the function f(xf(x,y)
y)
changes as a function of changes in the arguments x
and y.
• The gradient vector points in the direction of
maximum change.g
• The length of this vector indicates the size of the
gradient:
INF 4300 7
• Horisontal edges:
– Compute gx(x,y)=Hx*f(x,y)
– Convolve with the horisontal filter kernel Hx
• Vertical edges:
– Compute
p gt((x,y)=H
,y) y*f(x,y)
( ,y)
• Compute the gradient operator as:
g ( x, y ) = g x2 ( x, y ) + g y2 ( x, y ) Gradient-magnitude (kant-styrke)
⎛ g y ( x, y ) ⎞
θ ( x, y ) = tan −1 ⎜⎜ ⎟⎟ Gradient retning
Gradient-retning
⎝ x
g ( x , y ) ⎠
INF 4300 8
Repetition – Edge direction
• The direction of this vector is also an important
quantity.
• If α(x,y)
( ,y) is the direction of f in the point
p (x,y)
( ,y) then:
INF 4300 9
INF 4300 10
Hough transform
Hough-transform
INF 4300 12
Hough transform – basic idea
• This equation can obviously be rewritten as follows:
• W
We now considerid x and d y as parameters
t d a and
and db
as variables.
• This is a line in (a,b
a b) space parameterized by x and y.
– So: a single point in xy-space gives a line in (a,b) space.
• Another point (x,y
x y) will give rise to another line in
(a,b) space.
INF 4300 13
(x,y)-space
(a,b)-space
INF 4300 14
Hough transform – basic idea
• Two points (x(x,y)
y) and(z
and(z,k)
k) define a line in the (x,y)
(x y)
plane.
• These
ese twoo po
pointss g give
e rise
se to
o two
od different
e e lines
es in
(a,b) space.
• In (a,b) space these lines will intersect in a point
( ’ b’) where
(a’,b’) h a’’ is
i the
th rise
i and d b’ the
th intersect
i t t off the
th
line defined by (x,y) and (z,k) in (x,y) space.
• The fact is that all points on the line defined by (x,y)(x y)
and (z,k) in (x,y) space will parameterize lines that
intersect in (a’,b’) in (a,b) space.
• Points that lie on a line will form a “cluster of
crossings” in the (a,b) space.
INF 4300 15
INF 4300 16
Hough transform - algorithm
INF 4300 17
Thresholded
edge images
Thresholding the
accumulator space
and superimposing
this onto the edge
image
INF 4300 18
Hough transform – polar
representation
i off lines
li
• In practical life we do not use the equation
• Rather,
Rather we use the polar representation of lines:
INF 4300 19
INF 4300 20
Hough transform and the polar
representation
t ti
• The polar (also called normal) representation of straight lines is
x cos θ + y sin θ = ρ
INF 4300 21
x
• Each curve in the figure represents
the familiy of lines that pass
through a particular point (xi,yi) in
th xy-plane.
the l
y
INF 4300 22
Matlab demo
• From (x
(x,y)
y) to (ρ θj)
( i,θ
INF 4300 23
INF 4300 24
Algorithm continued
• The cell (i(i,j)
j) corresponds to the square associated
with parameter values (θj, ρi).
a ea
• Initialize all cells
e s with value
a ue 0
0.
• For each foreground point (xk,yk) in the thresholded
edge image
– Let θj equal all the possible θ-values
• Solve for ρ using ρ=x cos θj +ysin θj
• Round ρ to the closest cell value,, ρq
• Increment A(i,q) if the θj results in ρq
• After this procedure, A(i,j)=P means that P points in
the xy space lie on the line ρj=x cos θj +ysin θj
xy-space
• Find line candiates where A(i,j) is above a suitable
threshold value.
INF 4300 25
INF 4300 26
Hough transform – example 2
• Example 2: 11x11 image and its Hough transform:
INF 4300 27
INF 4300 28
Hough transform – example 3
• Example 3: Natural scene and result of Sobel edge
detection followed by thresholding:
INF 4300 29
INF 4300 30
Hough transform – example 3
• Example 3: Original image and 20 most prominent
lines:
INF 4300 31
INF 4300 32
Hough transform - disadvantages
• Disadvantages:
– Computationally complex for objects with many parameters.
– Looks for only one single type of object
object.
– Can be “fooled” by “apparent lines”.
– The length and the position of a line segment cannot be
determined.
– Co-linear line segments cannot be separated.
INF 4300 33
INF 4300 34
Hough transform and edge linking
• How can we look for lines with a certain orientation?
1. Obtain a thresholded edge image
2
2. S
Specify
if subdivisions
bdi i i th ρθ-plane.
i the
in θ l
3. Examine the counts of the accumulator cells for high
pixel concentrations.
concentrations
4. Examine the relationship (principally for continuity)
between pixels in a chosen cell.
cell
• Continuity here normally means distance between
disconnected pixels. A gap in the line can be bridged if the
length of the gap is less than a certain threshold.
INF 4300 35
INF 4300 36
Hough transform for circles
• A circle in the xy-plane
xy plane is given by
( x − a )2 + ( y − b) = c 2
2
INF 4300 37
• Next exercise:
– Test Hough transform for equal size circles on the coins
g
image.
INF 4300 38
Hough transform – exercise 2
• Next exercise: The randomized Hough transform
transform.
– Simple idea (line case): From the edge image, pick two points.
– Find the ρ and θ corresponding to this set of points.
– I
Increment t th
the iindicated ( θ) cell.
di t d (ρ,θ) ll
– Once a cell reaches a certain (low) count, assume that an edge is
present in the image.
– Verify this
this.
– If truly present, erase this line from the image
– Continue until no more points or until the number of iterations
between two detections is to high high.
– Orders of magnitude faster than the ordinary transform.
INF 4300 39