title: unable to draw a line correctly using hough transformation in matlab
body: <p>I used <a href="http://rosettacode.org/wiki/Example:Hough_transform/MATLAB" rel="nofollow noreferrer">this </a> code for drawing lines using <code>Hough</code> tranform. In this code, there is a draw of the image in <code>Polar</code> space . I want to draw detected lines in <code>Cartesian</code> space. Thus, with the help of <a href="https://stackoverflow.com/questions/18951713/draw-the-lines-detected-by-cvhoughlines">this explanation</a> I wrote my code like this:</p>
  <pre><code>imBinary = flipud(edge(rgb2gray(im),'sobel'));
  [imWidth,imLenght]=size(imBinary);
  [interestPointY , interestPointX] = find(imBinary);
  numberOfInterestingPoints=numel(interestPointX);
  maxRadius=sqrt(imWidth^2 + imLenght^2);
  polarRadius=(-maxRadius:1:maxRadius);
  polarTheta=(-pi/2:(1/200):pi/2);
  numberOfPolarThetas=numel(polarTheta);
  houghMatrix=zeros(numel(polarRadius),numberOfPolarThetas);
  polarAccumulator = zeros(numberOfInterestingPoints,numberOfPolarThetas);
  cosine = (0:imWidth-1)'*cos(polarTheta);
  sine = (0:imLenght-1)'*sin(polarTheta);
  polarAccumulator((1:numberOfInterestingPoints),:) =cosine(interestPointY,:) + sine(interestPointX,:);
  for i = (1:numberOfPolarThetas)
      houghMatrix(:,i) = hist(polarAccumulator(:,i),polarRadius);
  end
  radiusDetect=[];angleDetect=[];
  houghBinaryMax = imregionalmax(houghMatrix);
  [Potential_radius ,Potential_angle] = find(houghBinaryMax == 1);
  %[radiusIndex angleIndex] = find(houghMatrix &gt; 0);
  houghTmp= houghMatrix - lineThreshold;
  for cnt = 1:numel(Potential_radius)
      if houghTmp(Potential_radius(cnt),Potential_angle(cnt)) &gt;= 0
          radiusDetect = [radiusDetect;Potential_radius(cnt)];
          angleDetect = [angleDetect;Potential_angle(cnt)];
      end
  end
  radius=polarRadius(radiusDetect);
  deg=polarTheta(angleDetect);
  %find two points in cartesian space
  x=radius.*cos(deg);
  y=radius.*sin(deg);
  x1=x+5.*cos(deg);
  y1=y+5.*cos(deg);
  imshow(imBinary);
  hold on;
  plot([x x1],[y y1]);
  </code></pre>
  <p>Unfortunately I did not get the correct lines and my image in like this:<a href="https://i.stack.imgur.com/QgDMi.png" rel="nofollow noreferrer">the blue lines are detected</a></p>
  <p>My question is what the mistake is that I cannot draw lines correctly?</p>