hough - hough transform for line detection |
[ht, rho_range] = hough(imbin) |
imbin |
binary image array (foreground equals 1) |
ht |
Hough transform accumulation matrix. Rho varies along rows; theta varies along columns. Theta range is 0-179 degrees w/ 180 samples. |
rho_range |
Vector containing the range of radius values. Equals -rmax:rmax, where rmax is the maximum radius possibly found in the input image. |
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. Negatives rho's point to the upper half of the image. |
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); |
There are no parameters for controlling the sampling of the parameter space. Also, the routine is too slow even for medium-sized images. It's purpose is for prototyping. When the function gets better, it will be transcribed to C language. |
"Shape Analysis and Classification", L. da F. Costa and R. M. Cesar Jr., CRC Press. |
"Practical Computer Vision using C", J. R. Parker, Wiley. |
Ricardo Fabbri <rfabbri@if.sc.usp.br> |
The latest version of the Scilab Image Processing toolbox can be found at |
http://siptoolbox.sourceforge.net |
ihough, drawline, edge |