• No results found

APPLICATION OF THE HOUGH TRANSFORM by Kyewook Lee

N/A
N/A
Protected

Academic year: 2022

Share "APPLICATION OF THE HOUGH TRANSFORM by Kyewook Lee"

Copied!
14
0
0

Loading.... (view fulltext now)

Full text

(1)

APPLICATION OF THE HOUGH TRANSFORM

by Kyewook Lee

University of Massachusetts, Lowell

January 2006

(2)

ABSTRACT

In this paper, I set out to implement the Hough algorithm in C. The Hough Transform is a line detection algorithm by Paul Hough. This algorithm was developed from slope- intercept parameters. The Generalized Hough Algorithm using angle-radius was developed by Duda and Hart. In this paper, both the Classic and Generalized Hough Transform will be discussed. How the algorithm is efficiently used will also be discussed.

1. INTRODUCTION

The Hough Transform is an algorithm that can provide a significant solution to the problems associated with line detection and definition. It is defined by the parametric representation used to describe lines in the picture plane. It was introduced by Paul Hough in 1962 and patented by IBM. The transform parameterizes a description of a feature at any given location in the original image space. Hough used slope-intercept parameters exclusively. Unfortunately, this has its limitations, because when the slope is horizontal or vertical, unique problems exist, and this requires special treatment. The Hough Transform universally used today was modified by Richard Duda and Peter Hart in 1972. This modification is generally called a "Generalized Hough Transform". Duda and Hart suggested using angle-radius rather then slope-intercept parameters [8].

The Hough Transform is composed of two parts:

a) Classical Hough Transform, which is applicable to lines and curves that are defined by slope-intercept parameters.

b) Generalized Hough Transform (modified by Duda and Hart) for images which are defined by angle-radius parameters.

In this paper, I will define the Hough Transform and the concept of The Generalized Hough Transform. Also, I will explain the implementation of the code that I have created.

Finally, I will discuss the threshold chosen for detection, and how it is selected.

2. THE HOUGH TRANSFORM

The Hough Transform is defined by the parametric representation used to describe lines in the picture plane. Duda and Hart [1972] suggested using angle-radius rather then slope-intercept parameters [8]. In this section, it will be discussed Classical Hough Transform and how the accumulator array works. Next, it will be showed the concept of The Generalized Hough Transform.

(3)

2.1 The Classic Hough Transform Using the Accumulator Array

Figure 1

The simplest representation of a line is in the form of a slope-intercept, y = ax + b, where

“a” is the slope of the line and “b” is the y-intercept. For example, Figure 1 shows 3 points on a 5X6 bitmap. Given this bitmap, we can define points A(1,2), B(2,4) and C(3,6). Point A can have a family of lines passing through it, and this can be expressed by the formula y = ax + b. In this formula, when we apply the values of A(1,2) to x and y, then a and b become parameters for the family of lines passing through A. Given this characterization of a line, we can then iterate through any number of lines that pass through a given point [4]. Therefore, with the three points in the image, A(1,2); B(2,4) ; C(3,6),

at A(1,2)

for y = ax + b we apply 1,2, to x, y, resulting in b = 2 – 1a at B(2,4)

for y = ax + b we apply 2,4, to x, y, resulting in b = 4 – 2a at C(3,6)

for y = ax + b we apply 3,6, to x, y, resulting in b = 6 -3a

Thus, for values of “a” from 1 to 5 (because the width of bitmap is 5), “b” will be as follows:

When a = 1 the corresponding value of b = 1 When a = 2 the corresponding value of b = 0 When a = 3 the corresponding value of b = -1 When a = 4 the corresponding value of b = -2 When a = 5 the corresponding value of b = -3 These results are then incorporated into an Accumulator Array.

(4)

At the beginning, the Accumulator Array is initialized to zero for all cells. After that, for every value of “a” with a corresponding value of “b”, the value of that cell is incremented by one.

a\b -6 -5 -4 -3 -2 -1 0 1 2 3

1 0 0 0 0 0 0 0 1 0 0

2 0 0 0 0 0 0 1 0 0 0

3 0 0 0 0 0 1 0 0 0 0

4 0 0 0 0 1 0 0 0 0 0

5 0 0 0 1 0 0 0 0 0 0

(We have arbitrarily chosen values of b from -6 to +3, since all values of b lie between those two numbers.)

Similarly, using the same formula, b = 4 - 2a,

When a = 1 the corresponding value of b = 2 When a = 2 the corresponding value of b = 0 When a = 3 the corresponding value of b = -2 When a = 4 the corresponding value of b = -4 When a = 5 the corresponding value of b = -6

a\b -6 -5 -4 -3 -2 -1 0 1 2 3

1 0 0 0 0 0 0 0 1 1 0

2 0 0 0 0 0 0 2 0 0 0

3 0 0 0 0 1 1 0 0 0 0

4 0 0 1 0 1 0 0 0 0 0

5 1 0 0 1 0 0 0 0 0 0

Thus, it is clear that when a = 2 and b = 0, the value entered in the corresponding cell in the Accumulator Array is 2 (incremented from 1). Since 2 is the highest value of all the numbers in the Accumulator Array, this indicates that A(1,2), and B(2,4) are valid points.

We can now draw a line connecting A and B. The resulting line is y = 2x + 0.

If you draw all possible lines that pass through point A, some of these will also pass through points B and C. Similarly, some of the lines that pass through point B will also pass through points A and C. Cells are incremented in the accumulator array when lines pass through multiple points. At the end of the accumulation process, the cell that has the highest value represents the line that passes through the most number of points in the source image array.

However, this method has its drawbacks. If the line is horizontal, then “a” is 0, and if the line is vertical, then “a” is infinite. So, a more general representation of a line will be ρ = x cosθ + y sinθ, although this is not a representation of the line itself. This is now

(5)

discussed in the presentation of the Generalized Hough Transform.

2.2 The Generalized Hough Transform

For the purposes of executing a Hough Transform, particularly a Generalized Hough Transform, it needs to convert Cartesian coordinates [x,y] into polar coordinates [ρ,θ], where ρ is the line connecting the polar coordinate to the origin where the x-axis intersects the y-axis, and where θ is the angle between the x axis and ρ.

Figure 2

[From Pratt, Digital Image Processing, Wiley & Sons]

In the figure above, (a) shows data in Cartesian space and (b) shows data in polar space.

Using the formula,

ρ = xcosθ + ysinθ, ………… (1) the transform occurs from a line to a point.

(6)

Figure 3

[From Pratt, Digital Image Processing, Wiley & Sons]

In (c), the Cartesian representation is then used to generate a family of lines which intersect at the source point. This point has a family of lines emanating from a common point. When we plot the coordinates of any given point in polar space against each other, we get the curve depicted in (d).

Figure 4

[From Pratt, Digital Image Processing, Wiley & Sons]

In (e), we have 3 points, A, B and C. When plotting the curves for the three points in polar coordinates, these 3 points will have three curves that intersect at (ρ0,θ0). The intersection at (ρ0,θ0) confirms A, B and C as valid points. Thus, a valid line will pass through A, B and C.

(7)

Figure 5

[From Pratt, Digital Image Processing, Wiley & Sons]

Figure 5 illustrates the transformation of lines from Cartesian space to Polar space.

Print (a) and (b) show 3 points – low density.

Print (c) and (d) show a solid line – high density.

Print (e) and (f) show a dotted line – medium density.

The point of intersection of the curves in b, d, and f represents the rho-theta values of the line that is discovered.

(8)

3. GENERALIZED HOUGH TRANSFORM IMPLEMENTATION

While the Classical Hough Transform allows for easy transformation, the Generalized Hough Transform requires a more complicated process. This section presents my C implementation of the algorithm.

3.1 Cartesian Representation of Input Data

A sample image on a 25X25 bitmap on a 2D array will show, for example:

0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

This would be an input in Cartesian space.

3.2 Accumulate ρ-θ Array

The Duda and Hart modification translates Cartesian coordinates to Polar coordinates, thus translating A[x,y] to [ρ,θ]. The reason for doing this is to overcome difficulties presents when x equals 0 or y equals 0.

This transform precisely defines the input as Cartesian coordinate entries,

“ImgArr[i][j]”, and processes it by applying the formula ρ = x cos θ + y sin θ

The result of that processing is entered into an Accumulator Array. The Array is initialized to zero in every cell. The following function, rho_theta_hough_transfrom, performs this operation.

(9)

void rho_theta_hough_transform() {

int i,j,Om;

double Th ; double sinTh ; double cosTh ; int r ;

/* rho-theta Accumulator Array Initialize */

for ( i = 0 ; i < OMEGA ; i ++ ) for ( j = 0 ; j < THETA ; j ++ ) Tr2_Acc_Ary[i][j] = 0 ;

for ( i = 0 ; i < 25 ; i ++ ) {

for ( j = 0 ; j < 25 ; j ++ ) {

/* input Image Array */

if ( ImgArr[i][j] == 1 ) {

for ( Om = 0 ; Om < OMEGA ; Om ++ ) {

Th = CONV * Om ;

sinTh = sin(Th) ; cosTh = cos(Th) ;

/* ρ = x cos θ + y sin θ */

r = (int)( i * sinTh + j * cosTh ) ; if ( r < 0 ) r = abs(r) + MIDDLETH ;

/* add into the Accumulator Array */

Tr2_Acc_Ary[Om][r] += 1 ; }

} } } }

3.3 Parsing/ Mining the Rho-Theta Array for Local Maxima

As mentioned in section 3.1, the input in this case has a negative slope. This is processed in section 3.2. The result of the processing is fed into the Accumulator Array.

The result shows that vertical is theta and horizontal is rho. The theta is between 0 and 180 degrees, and the range for rho is:

(10)

As seen below, values of theta range between 42 and 50, and the value of rho is 7.

3.4 Converting from Rho-Theta Maxima to Slope-Intercept Representation

Using the formula, it is converted

ρ = x cos θ + y sin θ to …………

θ ρ θ

θ

sin sin

cos +

= x

y to …………

θ ρ θ sin tan

1 +

= x

y

void rho_theta_print_Arr() {

int i,j ;

double sinTheta , cosTheta ;

(11)

printf( " ---- p(rho) = x cos theta + y sin theta --- \n" );

for ( i = 0 ; i < OMEGA ; i ++ ) {

for ( j = 0 ; j < RHOMAX ; j ++ ) {

if ( Tr2_Acc_Ary[i][j] >= threshold_rho_theta ) {

if ( i == 0 ) {

printf( " Vertical line Rho is [%d]\n", j );

continue ; }

if ( i == 0 ) {

printf( " 2 y = (%.2f)x + (%.2f) \n", ( (cosTheta / sinTheta ) * -1) , ( j / sinTheta ) ) ; }

else {

printf( " 3 y = (%.2f)x + (%.2f) \n", ( (cosTheta / sinTheta ) * -1) , ( - (j-MIDDLETH) / sinTheta ) ) ; }

}

} } }

printf( " Maxima [%d] \n", max_acc_num );

printf( " ---- p(rho) = x cos theta + y sin theta end --- \n" );

}

3.5 Presenting the discovered line into the Accumulator Array

The input above results in the following:

---- p(rho) = x cos theta + y sin theta --- 1 y = (-1.15)x + (9.15)

1 y = (-1.11)x + (8.97) 1 y = (-1.07)x + (8.80) 1 y = (-1.04)x + (8.64) 1 y = (-1.00)x + (8.49) 1 y = (-0.97)x + (8.34) 1 y = (-0.93)x + (8.20) 1 y = (-0.90)x + (8.07)

(12)

4. DISCUSSION

The challenge of the Hough transform is to allow the user to arrive at values for ρ and θ to facilitate line detection, and to select the most appropriate threshold to apply in order to detect the line.

My challenge is to design an algorithm that will give me a series of borders by selecting the appropriate gray scale. One possibility is to convert all images of varying density to gray scale, and to assign specific values to each “level” of the gray scale. The algorithm necessary to do this is complicated, and will not be discussed here.

My C program presently is designed for only a single input line, with a manually entered threshold for detecting the maxima.

5. CONCLUSION

The Hough Transform is a mathematical tool that greatly enhances the process of line detection. This is essential to every computer vision system.

At the present time, vision system image clarification poses continuing challenges to all computer engineers. The use of the Hough transform, combined with appropriate algorithms, will go a long way to contribute to the final product -- vision clarity.

Acknowledgement

I want to thank my advisor Dr Fred G. Martin of the Computer Science Department for his very helpful suggestions, criticism, and insightful comments. Most of all, I want to thank him for his great patience and kindness to me.

I want to acknowledge the generosity of the Computer Science Department for their support in granting me a Teaching Assistant appointment.

Finally, I also want to thank John W. Wang, MD, for correcting my English.

(13)

Reference

1. Ballard,DH, Brown,CM “Computer Vision” Prentice-hall, 1982 2. William K. Pratt “Digitial Image Processing” third-edition,

John Wiley & Sons, 2001

3. http://cs-alb-pc3.massey.ac.nz/notes/59318/l10.html 4. Hough Transform

http://planetmath.org/encyclopedia/HoughTransform.html 5. Hough Transform

http://www.netnam.vn/unescocourse/computervision/62.htm 6. xhoughtool

http://www2.lut.fi/dep/tite/XHoughtool/xhoughtool.html.

Petri Hirvonon, Jouni.Ikonen,Pekka kultanen, Heikki kalvianine.

Lappeenranta University of Technology

7. W.Eric L.Grimson “Object Recognition by Computer” MIT Press, 1990

8. R. O. Duda and P. E. Hart “Use of the Hough Transformation to Detect Lines and Curves in Pictures”, Communication of the ACM, 15, 1, January 1972, 11-15

9. Phillip D. S. Thoren Phission Concurrent version Processing System http://www.phission.org

(14)

Appendix

Hough Transform Sample Program Instructions

Sample Program : http://www.cs.uml.edu/~lkyewook/hough/

There are two requirements in executing this program:

a) using binary image file as an argument ./sht nslope.bimg

b) using binary image file with slope-intercept threshold and rho-theta threshold.

./sht nslope.bimg 5 5

input:

0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

---- p(rho) = x cos theta + y sin theta --- 1 y = (-1.15)x + (9.15)

1 y = (-1.11)x + (8.97) 1 y = (-1.07)x + (8.80) 1 y = (-1.04)x + (8.64) 1 y = (-1.00)x + (8.49) 1 y = (-0.97)x + (8.34) 1 y = (-0.93)x + (8.20) 1 y = (-0.90)x + (8.07) 1 y = (-0.87)x + (7.95)

Maxima [8]

---- p(rho) = x cos theta + y sin theta end ---

References

Related documents

As for the organization of the paper, in the first sections we review some facts about exponential transforms, quadrature domains and meromorphic resultants which will be needed in

When Stora Enso analyzed the success factors and what makes employees &#34;long-term healthy&#34; - in contrast to long-term sick - they found that it was all about having a

The observations of the walls are extracted using the range-weighted Hough transform (RWHT) and the position of the robot is continuousb updated using an extended Kalman

Regarding the questions whether the respondents experience advertising as something forced or  disturbing online, one can examine that the respondents do experience advertising

Vickers, “Combined source channel coding of images using the block cosine transform,” IEEE Transactions on Communications, vol.. Cover, “Broadcast Channels,” IEEE Transactions

Different smoothing techniques were tried, including standard image processing filters (Gaussian and median filters), but the best performing filter was a standard 11-tap low-pass

We set out to answer the question of how Shor’s algorithm can factorize integers in poly- nomial number of operations using unitary quantum transformations, how this algorithm

We recommend for the further researches to examine the the considered method for other types of the exotic options, to implement the Laplace transform on the Merton model and