Lines detection

Hi All, the following is a quite difficult task so any kind of help, even simple, will be much appreciated.

After color segmentation I generated the following image

I need to get lines that approximates white areas (roads), as shown in the following hand-made image

Using probabilistic HoughLines with following parameters (image and lines are Mat instances):

Imgproc.HoughLinesP(image, lines, 2, Math.PI /180, 200, 100, 5);


I get the following result:

I tried several combinations of parameters and shown result seems to be the best that I can achieve.

My questions:

1. Overall, what do you think of this approach ?

2. Any idea on how to select 'strongest' lines after HoughLines transform ? Is there any way to cluster every bundle of lines into a single significative line ?

Thanks

edit retag close merge delete

clustering the results to 13 centers ? seems like a good idea, did you try that ?

( 2017-12-18 14:16:04 -0500 )edit

There should be 14 centers, since there are 14 segments. The main problem is that I don't know how to deal with object lines. For sure I know how iterate each line to get start/end points

Point pt1 = new Point();
Point pt2 = new Point();
double[] data;
for (int i = 0; i <lines.rows(); i++){
data = lines.get(i, 0);
pt1.x = data[0];
pt1.y = data[1];
pt2.x = data[2];
pt2.y = data[3];
Imgproc.line(result, pt1, pt2, new Scalar(0, 255, 0), 1);
}


but that said I am stuck ...

( 2017-12-18 15:06:14 -0500 )edit

kmeans, dbscan, em, chinese_whispers, partitioning, did you try any of that ? (i still think, clustering is a good idea) (tried, poor results)

( 2017-12-18 15:11:00 -0500 )edit
1

there is an additional complexity thay I omitted. I have a set of images (the one I posted is just an example), each could have a different number of centers. For kmeans it think centers should be known before. What is chinese_whispers ? never heard before

( 2017-12-18 15:36:06 -0500 )edit

Hi, my suggestion is clustering too... But I recommend that you use "superpixel", like SLIC. The SLIC will automatically figure out the centroids in a degree of "understanding the image".

Here is the comparision between some superpixel methods:

( 2017-12-21 05:56:19 -0500 )edit

Hi, my suggestion is clustering too... But I recommend that you use "superpixel", like SLIC. The SLIC will automatically figure out the centroids in a degree of "understanding the image".

Here is the comparision between some superpixel methods:

( 2017-12-21 05:56:26 -0500 )edit

thanks moHe. Do you have concrete example ?

( 2017-12-21 11:22:55 -0500 )edit

I tried dbscan using Apache Maths. I am able to cluster centers of Houghlines, but I am not able to return back to lines from my clustered points.

( 2017-12-21 11:27:58 -0500 )edit

Sort by ยป oldest newest most voted

Well, after hard work I have a solution. I look forward your inputs, ideas and improvements.

First, I did some noise removal to obtain cleaner lines

Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7));
Imgproc.morphologyEx(grayOnly, grayOnly, Imgproc.MORPH_OPEN, se);


Then HoughLines transform as I did before, this time the image is cleaner

I have drawn the lines with a large thickness to obtain a single object in the image

Imgproc.line(result, pt1, pt2, new Scalar(0, 0, 0), 35);


Last step, the most important, I applied Zhang Suen thinning alghoritm (skeletonization). I found a good reference here

The final result is the following

The approximation seems good

more

1

Hi, actually, if you use python, you can easily from skimage.morphology import skeletonize.

( 2017-12-21 21:12:42 -0500 )edit

Yes, but I always use Java :) even if it is the worst choice with Opencv

( 2017-12-22 01:40:15 -0500 )edit

Zhang-Sueng is now on ximgproc, check the docs.

( 2019-10-08 09:15:17 -0500 )edit