hough_lines

Upload: rushi-desai

Post on 08-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 hough_lines

    1/4

    Hough Transform for Straight Lines

    Mini-project in Image Processing, 7th semester 2007

    By Jeppe Jensen. Group 721

    The Hough transform is a technique used to find shapes in a binary digital image. By Hough Transform

    it is possible to find all kind of shapes that can be mathematical expressed, for instance lines, circles and

    ellipses, but only straight lines will be considered here.

    If having a white pixel in a binary image, infinity many straight lines can go through that single pixel,

    and each of these lines can go through other white pixels in the same image, and the more white pixels

    on the same line the more is this line represented in the image. This is the principle of the Hough

    transform for straight lines.

    As mentioned above a shape can be found if a mathematical expression can be set for the shape, and in

    this case where the shape is a straight line, an expression can be set as:

    y = ax+b (1)

    Where a is the slope, and b is where the line intersects the y-axis. These parameters, a and b, can

    be used to represent a straight line as single point (a, b) in the parameter-space spanned by the two

    parameters a and b. The problem by represent a line as a point in the (a, b) parameter-space, is that both

    a and b goes toward infinity when the line becomes more and more vertical, and thereby the parameter-

    space becomes infinity large. Therefore it is desirable to find another expression of the line with some

    parameters that have limited boundaries. It is done by using an angle and a distance as parameters,

    instead of a slope and an intersection.

    If the distance (rho) is the distance from the origin to the line along a vector perpendicular to the line,

    and the angle (theta) is the angle between the x-axis and the vector (see Figure 1), Equation 1 can

    be written as:

    y =cos()

    sin()x+

    sin()(2)

  • 8/7/2019 hough_lines

    2/4

    2

    Figure 1: Rho and theta representation of a straight line. Each line has a unique

    parameter set (, ).

    The expressions here, instead of a and b, is found by trigonometrical calculations. To get an expression

    of, Equation 2 can be rearranged to:

    = xcos()+ y sin() (3)

    Contrary to when the parameters is a and b, the values that and can have are limited to: [0,180]

    in degrees or [0,] in radians, and [D,D] where D is the diagonal of the image. A line can

    then be transformed into a single point in the parameter space with the parameters and , this is also

    called the Hough space.

    If, instead of a line, having a pixel in an image with the position (x, y), infinity many lines can go

    through that single pixel. By using Equation 3 all these lines can be transformed into the Hough space,

    which gives a sinusoidal curve that is unique for that pixel. Doing the same for another pixel, gives

    another curve that intersect the first curve in one point, in the Hough space. This point represents the

    line, in the image space, that goes through both pixels. This can be repeated for all the pixels on the

    edges, in a edge detected image. Figure 2 shows an example with a RGB input image and the image

    after edge detection has been made. When the Hough transform is made on the image for all the whitepixels (edges) the lines that have most pixels lie on can be found, the result as the Hough space can be

    seen in Figure 3.

    The result of the Hough transform is stored in a matrix that often called an accumulator. One dimension

    of this matrix is the theta values (angles) and the other dimension is the rho values (distances), and each

    element has a value telling how many points/pixel that lie on the line with the parameters (rho, theta).

    So the element with the highest value tells what line that is most represented in the input image.

  • 8/7/2019 hough_lines

    3/4

    3

    (a) Input image (b) Edge detected image

    Figure 2: An example with an input image and the result of the edge detection,

    using the Canny edge detection.

    Hough transform

    Angle

    Distance

    0 20 40 60 80 100 120 140 160

    400

    300

    200

    100

    0

    100

    200

    300

    400

    Figure 3: The Hough space of the input image in Figure 2. The dark red points

    are the points with the highest number of intersections. Many dark red points are

    around 90 degrees, i.e. that the image has many horizontal lines.

    Implementation

    The Hough transform is implemented in Matlab. Even though Matlab has some built-in Hough func-

    tions, these are not used. Listing 1 shows the pseudo code of the Hough implementation. For a more

    detailed code, see the source code in houghLines.m.

    Listing 1: Pseudo code of the Hough Transform for straight lines

    1 l o a d i m ag e

    2 f i n d t h e e dg es i n t h e i mag e

  • 8/7/2019 hough_lines

    4/4

    4

    3 f o r a l l p i x e l s i n t h e im ag e

    4 i f t h e p i x e l ( x , y ) i s an e d ge

    5 f o r a l l t h e t h e t a a n g l e s

    6 c a l c u l a t e r ho f o r t he p i x el ( x , y ) and t h e a n g le ( t h e t a )

    7 i n cr e me n t t h a t p o s i t i o n ( rh o , t h e t a ) i n t h e a cc u mu l at o r

    8 sh ow t h e h ou gh s p a c e

    9 f i n d t h e h i g h e st v a lu e i n t h e a cc um u la t or

    10 draw t h e l i n e w it h t h e h i g h e st v a lu e i n t h e i n p u t i mag e

    References

    By Richard O. Duda & Peter E. Hart

    Use of the Hough Transformation to Detect Lines and Curves in Pictures, April 1971

    URL: http://www.ai.sri.com/pubs/files/tn036-duda71.pdf

    R. Fisher, S. Perkins, A. Walker and E. Wolfart

    Hough Transform, 2003

    URL: http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm

    Wikipedia - Hough transform

    URL: http://en.wikipedia.org/wiki/Hough_transform

    http://www.ai.sri.com/pubs/files/tn036-duda71.pdfhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htmhttp://en.wikipedia.org/wiki/Hough_transformhttp://en.wikipedia.org/wiki/Hough_transformhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htmhttp://www.ai.sri.com/pubs/files/tn036-duda71.pdf