% Hough transform 
clear 
x2=[0 0 0 0;
    1 1 1 1;
    0 0 0 0;
    0 0 0 0] % input image
[row,col]=size(x2);
% set up accumulator
rmax=round(sqrt((row-1)^2+(col-1)^2));
angles=0:45:179;
acc=zeros(rmax+1,length(angles));
%
for x=0:row-1 
  for y=0:col-1
    if(x2(x+1,y+1)~=0)
    for m=angles
      s=round(x*cosd(m)+y*sind(m));  
      if(s<=rmax && s>=0)
        c=round(m/45)+1;
        acc(s+1,c)= acc(s+1,c)+1;
       end
    end
  end
 end
end
acc

