Difference between MATLAB hough and my implementation -
i trying recreate matlab's hough function mine. code follows
function [h,t,r] = my_hough(x,dr,dtheta) rows = size(x,1); cols = size(x,2); d = sqrt((rows - 1)^2 + (cols - 1)^2); nr = 2*(ceil(d/dr)) + 1; diagonal = dr*ceil(d/dr); r = -diagonal:dr:diagonal; t = -90:dtheta:90-dtheta; ntheta = length(t); h = zeros(nr,ntheta); = 1:ntheta n1 = 1:rows n2 = 1:cols if x(n1,n2)==1 r = n2*cos(t(i)*pi/180) + n1*sin(t(i)*pi/180); [~,j] = min(abs(r-ones(1,nr)*r)); h(j,i) = h(j,i) + 1; end end end end end
where dr
, dtheta
distance , angle resolution. printing difference between hough table , matlab's there many zeros, there non-zero elements. idea why happening?
well, silly mistake...
r = n2*cos(t(i)*pi/180) + n1*sin(t(i)*pi/180);
must be
r = (n2-1)*cos(t(i)*pi/180) + (n1-1)*sin(t(i)*pi/180);
thanks weird matlab indexing.
Comments
Post a Comment