title: Circular Hough Transform using gradient
body: <p>I'm trying to implement hough transform algorithm to detect circles in a gray scale image. 
  I ran edge detector and used the gradient's orientation at each point in order to get the line on which the radius lies.
  Then, I've tried to accumulate votes for each circle with center (cX,cY) and radius r:</p>
  
  <pre><code>% run edge detection on image
  Edges = edgeDetect(img);
  % initialize accumulator matrix
  Acc = zeros(imgRows, imgCols, maxR);    
  % get indices of edge points
  edgePoints = find(Edges);
  % get number of edg points
  numOfEdges = size(edgePoints);
  
  for currEdge = 1 : numOfEdges
  
      % get edge cartesian coordinate
      [eY eX] = ind2sub([imgRows, imgCols], edgePoints(currEdge));        
      % find gradient's direction at this point
      theta = Directions(eY, eX);
  
      for r  = minR : maxR
  
          % find center point according to polar representation of circle
          cX = round( eX - r*cos(theta) );
          cY = round( eY - r*sin(theta) );
  
          % check if (cX,cY) is within image's boundaries
          if 1 &lt;= cX &amp;&amp; cX &lt;= imgCols &amp;&amp; 1 &lt;= cY &amp;&amp; cY &lt;= imgRows
  
              % found a circle with (cX,cY) as center and r as radius
              Acc(cY, cX, r) = Acc(cY, cX, r) + 1; % increment matching counter
  
          end            
      end        
  end
  </code></pre>
  
  <p>However, the maximum value in accumulator (Acc) is 10 - so I guess something's wrong with the way I count circles. I've tried debugging it but could not see where the problem is...
  Any ideas what could be wrong? Any help will be much appreciated!</p>