Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find 4 points next to the intersection of two lines

Let's say I have some bitmap data (in black) over which some lines have been hand drawn in vector format (in green). The lines roughly follow the shape of the bitmap data. In some places, the lines intersect.

So what I'm trying to do is, knowing the position of the green lines intersection, how I can find the position of A, B, C and D?

See below for some examples:

enter image description here

I'm not sure how to approach this problem given the random positioning of the lines and sometime they are not even inside the black shape. However, I guess there must be some way. Any suggestion?

like image 238
laurent Avatar asked Sep 20 '11 05:09

laurent


1 Answers

Simplest approach I can think of is this:

  1. Filter the image to remove the green line. A simple approach would be to use some sort of thinning that fills with the background color of the neighboring pixel(s).

  2. Now you should have an image which consists of only black (broad) lines and white background.

  3. Filter the image again using a corner detection algorithm, such as the Harris detector. This will give you the four corners.

Notes:

  1. Depending on the input data, you might get more than four corners. In any case it is a good idea to verify that the four corners you extracted are indeed possible corners of the intersection.

  2. Again, this is a quite rough approach, but if the input data is as clean as in your example pictures, and the distance between the green lines and the black lines is not too big, I think it might work.

like image 184
Hannes Ovrén Avatar answered Nov 15 '22 23:11

Hannes Ovrén