title: Shape Detection Using Hough Transform in Matlab
body: <p>I'm using a Properly working Matlab code (The original code is from <a href="http://www.mathworks.com/matlabcentral/fileexchange/9275-simple-shape-detection-using-hough-transform" rel="nofollow">here</a>) that uses Hough trnsform to detect basic shapes like round, square and triangle.Here below is the important code segment.</p>
  
  <pre><code>[H, theta,rho]=hough(S);
  </code></pre>
  
  <p>Above H is the Hough transform matrix and S is the Black and White image of the shape.</p>
  
  <pre><code>for cnt = 1:max(max(H))
      data(cnt) = sum(sum(H == cnt));
  end
  </code></pre>
  
  <p>Here is the shape detection part.</p>
  
  <pre><code>[maxval,maxind] = max(data);
  medval = median(data);
  
  [p]=polyfit(1:maxind-5,data(1:maxind-5),2);
  
  if maxval&lt;3*medval
      set(handles.txtResult,'string','Triangle');
  elseif  p(3)&gt;100
      set(handles.txtResult,'string','Square');
  else
      set(handles.txtResult,'string','Round'); 
  end
  </code></pre>
  
  <p>I can understand the "data"(which stores Hough Matrix intensity frequencies).  I just can't understand the logic it uses to detect the shape. <code>maxval&lt;3*medval</code> and <code>p(3)&gt;100</code></p>