Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display clear result after Hough Transformation?

I have the following image acquired after a Canny edge detection: Canny edge detection result

After Hough transformation is applied to it and I get this result:

enter image description here

This is very good result but I need just one line from each bundle so I can display that the object from the first picture resembles a triangle. My first decision was to calculate some sort of "average" line for each bundle. Each line is defined by an angle and a raduis. My way of finding the "average" line for each bundle is to calculate the average of the angles using this formula:

avgTheta = arctan(sum of sines of all thetas/sum of cosines of all theta)

I calculate the average raduis in the simplest way:

avgRadius = sum of all raduises / number of raduises

However the lines I get are not in the center of their bundles.

Can someone please advise for a better solution?

I am using this implementation of the Hough Transformation: Hough Transform

There is always the option to take one line of each bundle randomly, but I don't like it.

If my question is not clear please tell me in order to try to explain the problem better.

Thanks in advance.

like image 496
Vassil Kossev Avatar asked Jan 23 '26 10:01

Vassil Kossev


1 Answers

You could try this:

Take the average angle without any cosine, sine or arctan function. Just make sure that you handle the wrap. Based on the implementation you linked to it seems to me that you wrap at pi (180 degrees). In your image the bundle of almost vertical lines on the right side of the "island(?)" will be a good example of lines that are on both sides of the wrap.

Also you probably get the best result if you have weighted lines based on how many points they include from the Canny edge detection picture, and then use this weight in the average calculations. Maybe this is already done by having multiple lines with the same properties, I could not tell from your image or the linked code.

like image 131
Johan Avatar answered Jan 25 '26 00:01

Johan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!