Ask Your Question
3

Lines detection

asked 2017-12-18 11:58:34 -0600

procton gravatar image

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

image description

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

image description

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:

image description

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 flag offensive close merge delete

Comments

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

berak gravatar imageberak ( 2017-12-18 14:16:04 -0600 )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 ...

procton gravatar imageprocton ( 2017-12-18 15:06:14 -0600 )edit

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

berak gravatar imageberak ( 2017-12-18 15:11:00 -0600 )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

procton gravatar imageprocton ( 2017-12-18 15:36:06 -0600 )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:

moHe gravatar imagemoHe ( 2017-12-21 05:56:19 -0600 )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:

moHe gravatar imagemoHe ( 2017-12-21 05:56:26 -0600 )edit

thanks moHe. Do you have concrete example ?

procton gravatar imageprocton ( 2017-12-21 11:22:55 -0600 )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.

procton gravatar imageprocton ( 2017-12-21 11:27:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
5

answered 2017-12-21 13:44:04 -0600

procton gravatar image

updated 2017-12-21 13:50:47 -0600

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);

image description

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

image description

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);

image description

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

The final result is the following

image description

The approximation seems good

image description

edit flag offensive delete link more

Comments

1

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

moHe gravatar imagemoHe ( 2017-12-21 21:12:42 -0600 )edit

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

procton gravatar imageprocton ( 2017-12-22 01:40:15 -0600 )edit

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

nicolasabril gravatar imagenicolasabril ( 2019-10-08 09:15:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-18 11:58:34 -0600

Seen: 2,090 times

Last updated: Dec 21 '17