Thursday, 19 June 2014

Circular hough Transfrom matlab code


%E-Edge image which is binary image
%distMax=diagonal
[iHeight,iWidth]=size(E);
%max possible distance from origin
distMax=round(sqrt(iHeight^2+iWidth^2);
%range of theta values
theta=-90:1:89
rho=-distMax:1:distMax;
%alocate accumulator array
H=zeros(length(rho),length(theta));

for ix=1:iWidth
   for iy=1:iHeight
      if E(iy,ix)==0

      % fill accumulator
       for iTheta=1:length(theta)
           t=theta(iTheta)*pi/180;  %get angle in radius

            %calculate distance from origin, given angle
             dist=ix*cost(t)+iy*sint(t);

             % find rho value closest to this
             [d,iRho]=min(abs(rho-dist));
             if d<=1
               %inc accumulator array
               H(iRho,iTheta)=H(iRho,ITheta)+1;
             end
           end
        end
     end
 end

No comments:

Post a Comment