title: Explanation of a Hough accumulator that does not match image
body: <p>I was having fun with image processing and hough transforms on Octave but the results are not the expected ones.
  Here is my edges image: <img src="https://i.stack.imgur.com/7Y6KF.png" alt="I am expecting local maxima for angles with values around 0/180deg and 90/270deg">
  and here is my hough accumulator (x-axis is angle in deg, y-axis is radius): <img src="https://i.stack.imgur.com/6ryaa.png" alt="The local maxima are around 100deg and 270deg">
  I feel like I am missing the horizontal streaks but there is no local maximum in the accumulator for the 0/180 angle values.</p>
  
  <p>Also, for the vertical streaks, the value of the radius should be equal to the x value of the edge's image, but instead the values of r are very high:</p>
  
  <p>exp: the first vertical line on the left of the image has an equation of x=20(approx) -> r.r = x.x + y.y -> r=x -> r=20</p>
  
  <p>The overall resulting lines detected do not match the edges at all:</p>
  
  <ul>
  <li>Acculmulator with detected maxima:<img src="https://i.stack.imgur.com/6NaaW.png" alt="Maximas are stisfyingly detected"></li>
  <li>Resulting lines:<img src="https://i.stack.imgur.com/Yf3Cu.png" alt="radius values are too high and theta values are missing"></li>
  </ul>
  
  <p>As you can see the maximas of the accumulator are satisfyingly detected but the resulting lines' radius values are too high and theta values are missing.</p>
  
  <p>It almost looks like the hough transform accumulator does not correspond to the image...</p>
  
  <p>Can someone help me figure out why and how to correct it?
  Here is my code:</p>
  
  <pre><code>function [r, theta] = findScratches (img, edge)
  
  hough = houghtf(edge,"line", pi*[0:360]/180);
  threshHough = hough&gt;.5*max(hough(:));
  
  [r, theta] = find(threshHough&gt;0);
  
  %deg to rad for the trig functions
  theta = theta/180*pi; 
  %according to octave doc r range is 2*diagonal 
  %-&gt; bring it down to 1*diagonal or all lines are out of the picture
  r = r/2;
  
  %coefficients of the line y=ax+b
  a = -cos(theta)./sin(theta);
  b = r./sin(theta);
  
  x = 1:size(img,2);
  y = a * x + b;
  
  
  figure(1)
  imagesc(edge);
  colormap gray;
  hold on;
  for i=1:size(y,1)
  axis ij;
  plot(y(i,:),x,'r','linewidth',1);
  end
  hold off;
  
  endfunction
  </code></pre>
  
  <p>Thank you in advance.</p>