• Tidak ada hasil yang ditemukan

The Hough Transform

Dalam dokumen Digital Image Processing (Halaman 182-187)

Finding Simple Curves: The Hough Transform

8.2 The Hough Transform

The method from Paul Hough—originally published as a US Patent [111] and often referred to as the “Hough transform” (HT)—is a general approach to localizing any shape that can be defined para- metrically within a distribution of points [64, 117]. For example, many geometrical shapes, such as lines, circles, and ellipses, can be readily described using simple equations with only a few parameters.

Since simple geometric forms often occur as part of man-made ob- jects, they are especially useful features for analysis of these types of images (Fig. 8.2).

The Hough transform is perhaps most often used for detecting straight line segments in edge maps. A line segment in 2D can be described with two real-valued parameters using the classic slope- intercept form

y=k·x+d, (8.1)

Fig. 8.2 Simple geometrical forms such as sections of lines, cir- cles, and ellipses are often found in man-made objects.

162

8.2The Hough Transform

x y

d

p1= (x1, y1)

p2= (x2, y2)

y1=k·x1+d y2=k·x2+d

Fig. 8.3

Two points,p1andp2, lie on the same line wheny1 = kx1+dandy2=kx2+dfor a particular pair of parametersk andd.

wherekis the slope anddthe intercept—that is, the height at which the line would intercept the y axis (Fig. 8.3). A line segment that passes through two given edge pointsp1= (x1, y1) andp2= (x2, y2) must satisfy the conditions

y1=k·x1+d and y2=k·x2+d, (8.2) fork, d∈R. The goal is to find values ofkanddsuch that as many edge points as possible lie on the line they describe; in other words, the line that fits the most edge points. But how can you determine the number of edge points that lie on a given line segment? One possibility is to exhaustively “draw” every possible line segment into the image while counting the number of points that lie exactly on each of these. Even though the discrete nature of pixel images (with only a finite number of different lines) makes this approach possible in theory, generating such a large number of lines is infeasible in practice.

8.2.1 Parameter Space

The Hough transform approaches the problem from another direc- tion. It examines all the possible line segments that run through a single given point in the image. Every lineLj =kj, djthat runs through a pointp0= (x0, y0) must satisfy the condition

Lj:y0=kjx0+dj (8.3) for suitable values kj, dj. Equation 8.3 is underdetermined and the possible solutions forkj, dj correspond to an infinite set of lines pass- ing through the given pointp0 (Fig. 8.4). Note that for a givenkj, the solution fordj in Eqn. (8.3) is

dj=−x0·kj+y0, (8.4) which is another equation for a line, where nowkj, djare thevariables andx0, y0 are the constantparametersof the equation. The solution set {(kj, dj)} of Eqn. (8.4) describes the parameters of all possible linesLj passing through the image pointp0= (x0, y0).

For an arbitrary image point pi = (xi, yi), Eqn. (8.4) describes the line

Mi:d=−xi·k+yi (8.5) with the parameters −xi, yi in the so-called parameter or Hough space, spanned by the coordinates k, d. The relationship between

163

8Finding Simple Curves: The Hough Transform

Fig. 8.4 A set of lines passing through an image point. For all possi- ble linesLjpassing through the pointp0 = (x0, y0), the equationy0 = kjx0+dj holds for appropriate val- ues of the parameterskj, dj.

x y

p0

L1

L2

L3 L4

(x, y)imagespace and (k, d)parameter space can be summarized as follows:

Image Space(x, y) Parameter Space (k, d) Point pi= (xi, yi) ←→ Mi:d=−xi·k+yi Line Line Lj: y=kj·x+dj ←→ qj= (kj, dj) Point Each image pointpi and its associated line bundle correspond to ex- actly one line Mi in parameter space. Therefore we are interested in those places in the parameter space where lines intersect. The example inFig. 8.5illustrates how the linesM1 andM2 intersect at the position q12 = (k12, d12) in the parameter space, which means (k12, d12) are the parameters of the line in the image space that runs through both image pointsp1andp2. The more linesMithat inter- sect at a single point in the parameter space, the more image space points lie on the corresponding line in the image! In general, we can state:

IfNlines intersect at position (k, d) inparameter space, then N image points lie on the corresponding liney =kx+d in image space.

Fig. 8.5 Relationship between image space and parameter space.

The parameter values for all possible lines passing through the image pointpi= (xi, yi) in image space (a) lie on a single lineMiin parameter space (b). This means that each pointqj = (kj, dj) in parameter space corresponds to a single lineLjin image space. The intersection of the two linesM1,M2at the point q12= (k12, d12) in parameter space indicates that a lineL12 through the two pointsk12and d12exists in the image space.

x y

k d

p1= (x1, y1)

p2= (x2, y2)

M1:d=x1·k+y1 M2:d=x2·k+y2

q12= (k12, d12) L12

(a)x/yImage space (b)k/dParameter space

8.2.2 Accumulator Map

Finding the dominant lines in the image can now be reformulated as finding all the locations in parameter space where a significant num- ber of lines intersect. This is basically the goal of the HT. In order 164

8.2The Hough Transform

x

y d

k

(a) Image space (b) Accumulator map

Fig. 8.6

The accumulator map is a discrete representation of the parameter space (k, d). For each image point found (a), a discrete line in the parameter space (b) is drawn. This oper- ation is performedadditively so that the values of the array through which the line passes are incremented by 1. The value at each cell of the accu- mulator array is the number of parameter space lines that intersect it (in this case 2).

to compute the HT, we must first decide on a discrete representation of the continuous parameter space by selecting an appropriate step size for thek and d axes. Once we have selected step sizes for the coordinates, we can represent the space naturally using a 2D array.

Since the array will be used to keep track of the number of times parameter space lines intersect, it is called an “accumulator” array.

Each parameter space line is painted into the accumulator array and the cells through which it passes are incremented, so that ultimately each cell accumulates the total number of lines that intersect at that cell (Fig. 8.6).

8.2.3 A Better Line Representation

The line representation in Eqn. (8.1) is not used in practice because for vertical lines the slope is infinite, that is,k=. A more practi- cal representation is the so-calledHessian normal form (HNF)1 for representing lines,

cos(θ) +sin(θ) =r, (8.6) which does not exhibit such singularities and also provides a natural linear quantization for its parameters, the angleθ and the radius r (Fig. 8.7).

With the HNF representation, the parameter space is defined by the coordinates θ, r, and a point p = (x, y) in image space corre- sponds to the relation

r(θ) =cos(θ) +sin(θ), (8.7) for angles in the range 0 θ < π (see Fig. 8.8). Thus, for a given image point p, the associated radius r is simply a function of the angleθ. If we use the center of the image (of sizeM×N),

xr=

!xr yr

"

= 1 2·

!M N

"

, (8.8)

1 The Hessian normal form is a normalized version of the general (“alge- braic”) line equationAx+By+C= 0, withA = cos(θ), B = sin(θ), andC=−r(see, e.g., [35, p. 194]).

165

8Finding Simple Curves: The Hough Transform

Fig. 8.7 Representation of lines in 2D.

In the commonk, drepresen- tation (a), vertical lines pose a problem becausek = . The Hessian normal form (b) avoids this problem by repre- senting a line by its angleθ

and distancerfrom the origin. x x

y y

d

(x, y) (x, y)

k= d= ?

r

θ

y=kx+d x·cos(θ) +y·sin(θ) =r

(a) (b)

as the reference point for thex/yimage coordinates, then it is possi- ble to limit the range of the radius to half the diagonal of the image, that is,

−rmax≤r(θ)≤rmax, with rmax= 12

M2+N2. (8.9) We can see that the functionr(θ) in Eqn. (8.7) is the sum of a cosine and a sine function onθ, each being weighted by thexandycoordi- nates of the image point (assumed to be constant for the moment).

The result is again a sinusoidal function whose magnitude and phase depend only on the weights (coefficients) x, y. Thus, with the Hes- sian parameterization θ/r, an image point (x, y) does not create a straight line in the accumulator map A(i, j) but a unique sinusoidal curve, as shown inFig. 8.8. Again, each image point adds a curve to the accumulator and each resulting cluster point corresponds to to a dominant line in the image with a proportional number of points on it.2

Fig. 8.8 Image space and parameter space using the HNF represen- tation. The image (a) of size M×Ncontains four straight linesLa, . . . , Ld. Each point on an image line creates a sinusoidal curve in theθ/rpa- rameter space (b) and the cor- responding line parameters are indicated by the clearly visible cluster points in the accumula- tor map. The reference point xrfor thex/ycoordinates lies at the center of the image. The line anglesθiare in the range [0, π) and the associated radii riare in [rmax, rmax] (the lengthrmaxis half of the im- age diagonal). For example, the the angleθaof lineLais approximatelyπ/3, with the (positive) radiusra0.4rmax. Note that, with this param- eterization, lineLchas the angleθc2π/3 and theneg- ativeradiusrc ≈ −0.4rmax.

Image Space (x/y) Parameter Space (θ/r)

x +x

+y

y

x

y i

j m1 n1

xr

a a

b b

c

c

d d

rmax ra

θa rb

rc θc

M 2 M

2 N

2 N 2

+r

r rmax

rmax 0

0 0

π 0

π

π 2

π 2

θ

(a) (b)

2 Note that, inFig. 8.8(a), the positive direction of they-coordinate runs upwards (unlike our usual convention for image coordinates) to stay in line with the previous illustrations (and high school geometry). In practice, the consequences are minor: only the rotation angle runs in the opposite direction and thus the accumulator image in Fig. 8.8(b) was mirrored horizontally for proper display.

166

Dalam dokumen Digital Image Processing (Halaman 182-187)