Hough transform for detection of lines in images
[HT,RHO,THETA] = htl(IM) [HT,RHO,THETA] = htl(IM, M,) [HT,RHO,THETA] = htl(IM, M, N) [HT,RHO,THETA] = htl(IM, M, N, TRACE) [HT,RHO,THETA] = htl(...,'plot')
A real Xmax by Ymax matrix: the image to be analyzed.
A positive integer value: the desired number of samples along the radial axis (default : Xmax).
A positive integer value: the desired number of samples along the azimutal (angle) axis (default : Ymax).
A boolean (or a real scalar) if true (or nonzero),the progression of the algorithm is shown (default : %f).
A real M by N matrix: the Hough transform result.
when called with the additional string 'plot', htl displays HT using mesh.
A real row vector of size M: the radial coordinates.
A real row vector of size N: the azimutal angles (in radians).
From an image IM, computes the integration of the values of the image over all the lines. The lines are parametrized using polar coordinates.
The origin of the coordinates is fixed at the center of the image (in pixel coordinates), THETA is the azimutal angle and RHO is the distance to the origin of the coordinates.
Only the values of IM exceeding 5% of the maximum are taken into account (to speed up the algorithm).
N = 128; t = (1:N); y = fmlin(N,0.15,0.45); [IM,T,F] = tfrwv(y,t,N); //Draw the image clf; gcf().color_map = jetcolormap(128); //Draw the image subplot(211); grayplot(1:N,1:N,IM'),ax=gca(); xlabel(_("Time (pixels)")) ylabel(_("Frequency (pixels)")) //Draw the Hough transform result [HT,RHO,THETA] = htl(IM,64); subplot(212); grayplot(RHO,THETA,HT), xlabel(_("Radial coordinate")); ylabel(_("Polar angle")) xtitle(_("Hough transform")) //Locate the Highest HT value [m,ind] = max(HT); theta = THETA(ind(2));rho=RHO(ind(1)); xpoly(rho,theta,"marks"); // Draw the line set(gce(),"mark_style",2,"mark_size",2,"mark_foreground",color("red")); //Take care rho and theta correspond to an image coordinates in pixels xl = N/2-rho*sin(theta)+60*cos(theta)*[-1 1]; yl = N/2+rho*cos(theta)+60*sin(theta)*[-1 1]; sca(ax); xpoly(xl,yl); set(gce(),"foreground",color("red"),"thickness",3); legend("Detected line"); | ![]() | ![]() |