Reputation: 81
I am trying to find or think of an algorithm that finds a path from a thick line. I think the images make easier to understand what I am trying to do.
Given is a 2D array as the picture with values 0 and 1 and I am trying to find the nodes of the lines. Has anybody an idea?
Upvotes: 0
Views: 147
Reputation: 312
I recommend using the most famous python library for image treatment : Pillow. https://python-pillow.org/
Some questions to orientate you :
But what means "scanning the picture" ? That's the key question. You could check all lines of pixels (from the first line till the last line, and for each line, from left to right), each time you encounter a white pixel you record its coordinates and you record how many white pixels are aside this first white pixel. Doing that, you will get a table where all white pixels are located. Then, it's more about mathemtics than about programming.
Upvotes: 0
Reputation: 10151
You could follow the contour and nibble away pixel by pixel (checking that the connectivity stays intact).
If you cannot remove any more pixels, you have a 1 pixel line as wanted.
But the line will most likely have very few long linear segments (unlike in your example)
Upvotes: 1