SIP Toolbox

hough - Hough transform for line detection

Calling Sequence

[ht, rho_range] = hough(imbin)

Input Parameters

Output Parameters

Description

Function hough calculates the hough transform of a binary image. The coordinate system is centered in the image, and the Y axis points downwards. Theta grows from X axis to Y axis. Negative rhos point to the upper half of the image.

Examples

   initial_dir = PWD;
   chdir (SIPDIR + 'images');

   // ======= Example 1

   im = imread('star.bmp');
   im = bwborder(im);
   xbasc()
   imshow(im,2);

   h = hough(im);
   xbasc()
   imshow(h,[]);  // theta varies horizontally from 0 to 180

   ht = 1*(h>= 40); // threshold the hough space
   lim = ihough(ht,size(im)); // draw the detected lines
   xbasc()
   imshow(lim + 2*im +1, hotcolormap(4)) // detected lines shown in yellow


   // ======= Example 2: how to obtain the parameters
   //
   // creating a empty picture with a line at y = -90
   e = zeros(200,200);
   e(10,:) = 1;

   // (remember that the Y axis points downwards and is centered in the
   // middle of the image)

   // getting its hough transform, and finding the points 
   // corresponding to y=10
   [h, rrange] = hough(e);
   [r,c] = find(h == max(h))

   // Gets the parameters of the line
   theta = c - 1       // 90 degrees
   rho   = rrange(r)   // -90 rho (upper half of image)

   // thx to Herve Lombaert for inspiring example #2 !

   chdir(initial_dir);
   

Authors

Ricardo Fabbri <ricardofabbri (AT) users DOT sf DOT net>

Bibliography

"Shape Analysis and Classification", L. da F. Costa and R. M. Cesar Jr., CRC Press.

"Practical Computer Vision using C", J. R. Parker, Wiley.

Availability

The latest version of the Scilab Image Processing toolbox can be found at

http://siptoolbox.sourceforge.net

See Also

ihough,  radon,  drawline,  edge,