% bugfixed for houghf.c version 2002.10.05 http://www.gerox.com % version up can apply non square image version 2004.02.07 http://www.gerox.com close all;clear all xmax=120; ymax=240; rhomax=120; thetamax=120; xymax=sqrt(xmax*xmax+ymax*ymax); data=eye(ymax,xmax); data2=imrotate(data,20,'crop'); figure(1);subplot(2,2,1);imshow(data2); data2=data2+rand(size(data2)); data2=data2>0.9; figure(1);subplot(2,2,2) imshow(data2,[]); res=houghf(+data2,rhomax,thetamax); figure(2);mesh(res);axis tight y=1:ymax; [row,col,maxval]=find(res==max(res(:))); figure(2);hold on;plot3(col,row,res(row,col),'rp');hold off theta = pi/thetamax*(col-1); rho = (rhomax/2-row)*xymax/rhomax; x=(rho/cos(theta)-(-y+ymax/2)*sin(theta)/cos(theta))+xmax/2+1; figure(1);subplot(2,2,3);imshow(data2,[]); hold on plot(x,y,'linewidth',5); hold off