Function uses Standard Hough Transform to detect Lines in a binary image.
According to the Hough Transform, each pixel in image space corresponds to a line in Hough space and vise versa.This function uses
polar representation of lines i.e. x*cos(teta)+y*sin(teta)=p to detect
lines in binary image. upper left corner of image is the origin of polar coordinate system
Example :
[pdetect,tetadetect,Accumulator] = houghline(Imbinary,pstep,tetastep,thresh)
As mentioned in the help section of the code, the origin of polar coordinate system is top left corner of the image and the rho can not be negative, so I think the code already covers the entire span. Please let me know if I am missing something.
For more open source softwares related to computer vision, please visit http://www.computervisiononline.com/software
@ines, the new version should be corrected for that error. please try it out. You should not have any problem now unless you are using a very large image with very small increment for pdetect that causes the size of pdetect to increase drastically.
Unfortunately the bug posted on 13 Jun 2005 is still present and a real one, without this fix one will only find half the hough space. Further the improvement suggested on 30 Aug 2007 by Stijn Helsen does make a significant difference. I understand the original author might not be updating this anymore, it would be good if the community could take owner ship.
thank you for this code, but when i compile it i had some errors like :
line 45:elseif thresh < 3
error('threshold must be bigger than or equal to 3')
return;% error :this statement cannot be reached
end
line 76 77 :
pdetect = [];tetadetect = [];
for cnt = 1:length(Potential_p)
if Accumulatortemp(Potential_p(cnt),Potential_teta(cnt)) >= 0
%error: the variable 'pdetect' appears to change size on every lop iteration(same error for 'tetadetect')
pdetect = [pdetect;Potential_p(cnt)];
tetadetect = [tetadetect;Potential_teta(cnt)];
end
end
Good program, can be simplified and it can be made faster. But very helpful..
03 May 2008
Junho Lee
FOr Study
01 Nov 2007
priya t
29 Oct 2007
Vijay Kumar
17 Oct 2007
abbas emadi
05 Sep 2007
Jia Li
31 Aug 2007
Stijn Helsen
My previous comment was not completely correct. pmax shouldn't be p(1), but p(1)-pstep/2
30 Aug 2007
Stijn Helsen
Except for the bug (of determining half of the Hough space), the code can be made a lot faster by replacing the "find-method" for determining the p-index to calculation, for example : Indp = round(abs(roi+pmax)/pstep+1);
(where pmax is -p(1)) is a lot faster and as good.
27 Aug 2007
HAMNETT CGU
Thanks a lot!!
17 Aug 2007
Nong Minh Ngoc
Thanks so much !
14 Jun 2007
X. King
It's useful. Good job!
17 May 2007
reg zs
You are very kindness
26 Apr 2007
jing zuo
good
21 Mar 2007
gaurav goyal
gud
17 Dec 2006
zhao tong
you are very good
15 Dec 2006
lamya durain
I am not profesional in mat;ab yet ,but i want to thank you very much for your effort .
20 Jul 2006
akbar jafary
15 Mar 2006
ali mot
13 Jun 2005
Nicolas HUOT
Hi, I discovered a bug in your file. It was unable to detect Positive sloped lines. I fixed it, tell me if I'm right on this:
function [pdetect,tetadetect,Accumulator] = houghline2(Imbinary,pstep,tetastep,thresh)
%HOUGHLINE - detects lines in a binary image using common computer vision operation known as the Hough Transform.
%
%Comments:
% \ Function uses Standard Hough Transform to detect Lines in a binary image.
% \ According to the Hough Transform, each pixel in image space
% corresponds to a line in Hough space and vise versa.This function uses
% polar representation of lines i.e. x*cos(teta)+y*sin(teta)=p to detect
% lines in binary image. upper left corner of image is the origin of polar coordinate
% system.
%
%Usage: [pdetect,tetadetect,Accumulator] = houghline(Imbinary,pstep,tetastep,thresh)
%
%Arguments:
% \ Imbinary - a binary image. image pixels that have value equal to 1 are
% \ interested pixels for HOUGHLINE function.
% pstep - interval for radius of lines in polar coordinates.
% tetastep - interval for angle of lines in polar coordinates.
% thresh - a threshold value that determines the minimum number of
% pixels that belong to a line in image space. threshold must
% be bigger than or equal to 3(default).
%
%Returns:
% pdetect - a vactor that contains radius of detected lines in
% polar coordinates system.
% tetadetect - a vector that contains angle of detcted lines in
% polar coordinates system.
% Accumulator - the accumulator array in Hough space.
%
%Originally Written by :
% Amin Sarafraz
% Photogrammetry & Computer Vision Devision
% Geomatics Department,Faculty of Engineering
% University of Tehran,Iran
% sarafraz@geomatics.ut.ac.ir
%
%Bug fixed by:
% Nicolas HUOT
% Electrical Engineering and Computer Science Student
% UCLA (Los Angeles) and INPG (Grenoble)
% \ nicolas.huot@gmail.com
%
%May 5,2004 - Original version
%November 24,2004 - Modified version,slightly faster and better performance.
%June 13, 2005 - Positive sloped lines possible (Nicolas HUOT)
if nargin == 3
thresh = 3;
elseif thresh < 3
error('threshold must be bigger than or equal to 3')
return;
end
p = -sqrt((size(Imbinary,1))^2+(size(Imbinary,2))^2):pstep:sqrt((size(Imbinary,1))^2+(size(Imbinary,2))^2);
teta = 0:tetastep:180-tetastep;
%Creating the accumulator:
Accumulator = zeros(length(p),length(teta)); %creating the Accumulator
[yIndex xIndex] = find(Imbinary); %extract the points from the image
for cnt = 1:size(xIndex) %looping on the list of points of the image
Indteta = 0;
for tetai = teta*pi/180 %looping on the list of possible teta (in radians)
Indteta = Indteta+1;
roi = xIndex(cnt)*cos(tetai)+yIndex(cnt)*sin(tetai); %ro computed
if roi >= p(1) & roi <= p(end) %acceptable ro are filtered
\ temp = abs(roi-p); %computing the distances between the roi and the list of acceptable values
mintemp = min(temp); %picking the minimum of it
Indp = find(temp == mintemp); %finding the indexes of this value
Indp = Indp(1); %picking the first one
Accumulator(Indp,Indteta) = Accumulator(Indp,Indteta)+1; %hop, increasing the coresponding point in the Accu
end
end %end loop tetai
end %end loop image points
% Finding local maxima in Accumulator
AccumulatorbinaryMax = imregionalmax(Accumulator); %creating the array of regional max
[Potential_p Potential_teta] = find(AccumulatorbinaryMax == 1); %picking up the maximums
Accumulatortemp = Accumulator - thresh; %leveling the accu by the threshold
pdetect = [];tetadetect = [];
for cnt = 1:length(Potential_p) %looping on the possible ro
if Accumulatortemp(Potential_p(cnt),Potential_teta(cnt)) >= 0 %if the minimum threshold is reached
pdetect = [pdetect;Potential_p(cnt)]; %append the new confirmed values
tetadetect = [tetadetect;Potential_teta(cnt)];
\ end
end
We are trying to detect a line in an image, we applied this hough transform., Now we got the accumulator point, please tell us how will we remap that accumulator points back to image space.
Updates
04 Sep 2012
Error handling/ Better documentation/ Evaluating the comment by Nicolas HUOT