2

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

PrazSam
  • 1,166
  • 2
  • 12
  • 20
  • This has to do with the model used to construct `H`. Can you post the code for computing `H` as well? – buzjwa May 04 '15 at 09:26
  • Thanks for mentioning it. I edited the question. Now I think there is no more confusion on `H`. It's the typical hough transform matrix. – PrazSam May 04 '15 at 11:03
  • You can find some more information in the code author's related [blog post](http://basic-eng.blogspot.com/2005/12/object-detection-using-hough-transform_06.html?m=1). It seems this method is rather heuristic and not guaranteed to work. I think there are some assumptions here on the size of the shape and of the image which are not mentioned in the function description – buzjwa May 04 '15 at 15:03
  • Yes I tried to find about it on the blog. He hasn't described it well. Thanks for the advice. It seems you are correct. I also feel that it is not the best method. – PrazSam May 04 '15 at 17:03
  • 1
    I think it's meant more as an illustrative, simple example. You can try running some shapes and plotting their Hough matrix and frequencies, and maybe these criteria will make more sense. I wouldn't count on it working on more general input, though. – buzjwa May 04 '15 at 18:07
  • I saw most of the people referring this Matlab program in most answers on Hough. That's why I tried to understand it. Ok I'll try to make more sense on it by giving different image files externally or I have to go for a another code. If you think this question and comments will help to others, feel free to vote up. Ok Thanks for the help. – PrazSam May 05 '15 at 02:16

0 Answers0