Let's say I have a shape like this:
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.
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:
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:
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....
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With