I am trying to recreate MATLAB's hough function with mine. My 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); for i = 1:Ntheta for n1 = 1:rows for 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
dtheta are distance and angle resolution. Printing the difference between my Hough table and MATLAB's there are many zeros, but there are also some non-zero elements. Any idea why this is happening?