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