0
votes

I'm implementing Hough-Radon transform in Matlab to detect some patterns (stright lines mostly). I've already implemented it, but the problem is that it also detects the "frame" as a line (see picture).

enter image description here

The code to implement this is basically:

[H,T,R] = hough(BW,'RhoResolution',0.6,'Theta',-90:0.5:89.5);
P  = houghpeaks(H,20,'threshold', ceil(0.1*max(H(:))));
lines = houghlines(BW,T,R,P,'FillGap', 15,'MinLength',50);

Where lines is a struct composed by the fields:

  • Starting point.
  • Ending point.
  • Angle Tetha
  • Distance Rho

Is there anything I could do to get rid of the four frame lines?

Edit:

The original picture before perform the Hough transform is:

enter image description here

1
Never seen this before. Are you sure those are not in BW? In any case, you can remove them from P because you know the parameters of these 4 lines.Cris Luengo
I've updated the question with the original picture before the Hough Transofrm. To remove them by the angle is impossible because the desired line has the same angle. And the points each time are diferent so cannot be removed by that way. any other idea?Pep
that's not the BW image because it's not binary. How do you binarize it?Cris Luengo
P contains both angle and distance for each line. You can find out what angle and distance correspond to these lines and remove them. Why do you say the points are different each time? What points? In the Hough space? Is it random???Cris Luengo
Regarding what I said about the points (which is the starting and ending point of each line), I have several images similar to that (but not equal), so each time I perform the hough transform and I got the lines, the "frame" lines are slighlty diferent. For example the first time starts in the position (1,1) and the next time in the (2,4). So I cannot filter them by removing an specific position because each time is diferent (and could be posible that the true line I want to detect is very near the frame).Pep

1 Answers

1
votes

The issue is with your preprocessing. Look at the binary image BW that you put into hough: it has those lines in it.

I recommend that you replace your binarization with something like this:

BW = imbinarize(I, 128);
BW = bwmorph(BW,'skel');