# Implement a hough for thick lines

Please suggest the best method for implement a function by hough for thick lines detection.

Note :

• Angles range[0 - 179].
• Angels zero and 179 are neighbors.

edit retag close merge delete

The basic function doesn't detect your line? Do you have an example of image?

( 2013-01-30 14:03:54 -0600 )edit

It is a public function that act in all situation.I edited my question and put the sample image.

( 2013-01-31 00:07:31 -0600 )edit

what do you mean by "a public function"?

( 2013-01-31 06:51:33 -0600 )edit

Sort by » oldest newest most voted

You could detect them as follows:

• run Canny --> you'll get two lines for the thick ones
• then HoughLines or HoughLinesP
• if you use HoughLines: you get a lines array represented by rho and theta. Thus, you can group by theta, then you get all lines which have the same angle, afterwards you group those togeter which differ from their rho-Value only by a small amount
• if you use HoughLinesP you would have to compute the slope yourself from the line-segment-ending points, then group those with a similar slope together and afterwards check how far the parallel lines are away from each other
more

If we run canny, for each thin line we have two line.When you run canny on the image how would you distingiush between the two top lines and the left line.

( 2013-01-31 07:14:26 -0600 )edit

Probably you meant that for each thick line you get two canny lines. Of course the above method doesn't work if you have also parallel thin lines next to each other and want to distinguish between a thick line. For this case I would suggest you to use Erosion (morphological operation), then the thick lines get smaller and the thin lines will disappear.

( 2013-01-31 10:51:19 -0600 )edit

I want to detect all lines simultaneously without disappearing any thin lines from image.

( 2013-02-01 01:49:27 -0600 )edit

Yet, you can solve it by applying erosion multiple times. 1. Save your old image. 2. Apply erosion so often that you won't detect any line any more 3. restore old image. 4. Iteratively erode the image one pass less than the before, you then will detect the thickest lines and you also know how thick they are from the number of erosions. 5. Remove these lines (or mask them out) in the image and start with step 4 again with one erosion pass less than before.

Alternatively you could vary the structuring element of the erosion process (thicker structuring elements denote thicker lines)

( 2013-02-01 03:20:18 -0600 )edit

However note, that this approach maybe pretty slow if you have a large image since you need to apply erosion several times. Maybe there exist a total different approach for detecting lines and distinguishing thick from thin parallel lines.

( 2013-02-01 03:21:36 -0600 )edit

Another idea came to my mind: Are your images always like the one above? Because then you could maybe search for connected components (findContours) and then compute the width and height for each component.

( 2013-02-01 03:26:09 -0600 )edit

Morphological operations is rejected because it damages the shape of lines & it is high order computation.How would you compute the width of contours when there are crossing lines.

( 2013-02-01 03:55:44 -0600 )edit

How should it damage the shape of the line? It hins it out that is all. I also don't think it is a high order computation. However you have a good point that crossing lines contradict working with connected components directly. but you could group the lines according to their line width as it is done in http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=5540041

( 2013-02-01 04:07:19 -0600 )edit

Look at the left line in the above picture.The thick lines are not neat. When lines are connected to each other and spread cross the image and width of thick lines is n,To get all line on the image you have to iterate n times the morphological operation. In some cases,There are not any thin line but you have to n times run the morphological operations.

( 2013-02-01 04:43:05 -0600 )edit

Yes, this is true and as I said, it depends on the pictures you have if that is suitable for you or not. But erosion itself is not difficult to compute and in general pretty fast. So for small images it should be fast enough, maybe also just downsampling of the image will remove thin lines enough that they won't be detected anymore.

( 2013-02-01 05:22:29 -0600 )edit

Official site

GitHub

Wiki

Documentation