Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding coordinates of points on the border of a shape

Let's say I have a shape like this:

enter image description here

After all the jokes of me wanting to draw beans are exhausted, I want to find the points on the border of the shape. I know there can be many, so a fair distance between them is accepted.

Is there an algorithm for such a need? Or a software? All the solutions I came up with involve a lot of manual work, especially if I want to draw a slightly different shape.

Stackoverflow wisdom, please help.

like image 282
Tudor Avatar asked Feb 07 '11 21:02

Tudor


2 Answers

You may simply scan the pixels horizontally and vertically to find color frontiers, or, if you want a more sophisticated and general solution, you may for example use the gradient method to detect edges:

enter image description here

Edit

Answering your comment, the image is just a bi-dimensional array, containing pixel values. You can test each pixel and select those having a specific color. Like this:

enter image description here

And the result are your edge pixels:

{{35, 107}, {35, 108}, {35, 109}, {35, 110}, {35, 111},
 {35, 112}, {35, 113}, {35, 114}, {35, 115}, {35, 116},
 {35, 117}, {35, 118}, {35, 119}, {35, 120}, {35, 121},
 {36, 103}, {36, 104}, {36, 105}, {36, 106}, {36, 107}, etc....
like image 76
Dr. belisarius Avatar answered Nov 12 '22 09:11

Dr. belisarius


It sounds like you're looking for "vectorization", or more precisely "bitmap vectorization". If you vectorize your bitmap, you'll get vector version of your shape, which will give you all the boundary coordinates.

If so, there are a number of solutions available, including AutoTrace: http://autotrace.sourceforge.net/

like image 2
payne Avatar answered Nov 12 '22 09:11

payne