# Thread: Skeletonization / thinning issue

1. Member
Join Date
Mar 2010
Posts
6
Rep Power
0

## Skeletonization / thinning issue

Hi all!
First : im working on a skeletonized picture

After skeletonization the lines are "snaky" and not straight.
My problem:
1. how to straighten out the lines?
2. how to remove the small unwanted branches sticking out everywhere?

Anyone got some ideas for this or know about some good reading on the topic?

2. Senior Member
Join Date
Mar 2010
Posts
266
Rep Power
5
to straighten out the lines, would you can try is have the various points on the line "attract" each other:

suppose you have a snaky line between x=0 to x=100, so it's a bunch of [x, y] points.

for every point, calculate something like
Java Code:
```// let points[] be all points, and index - the current index
double finalY = (points[index].y +
points[index-1].y / 2 + points[index+1]/2 +
points[index-2].y / 4 + points[index+2]/4) / 2.5;```
that way, the final position of every point depends on positions of its neighbors, and the line will straighten a bit.

for your other question, hard to say without looking at the actual image... can you upload the image somewhere and post a link?

3. Member
Join Date
Mar 2010
Posts
6
Rep Power
0
Hi and thanks for you answer!
I'm gonna play around with that and see if i can make something out of it.

I've attached two images:
Skeletons.jpg which is the binary image produced after several iterations of erosion and skeletonization.
On skeletons2.jpg i have identified what i'm actually after. So you can see that i have alot of "noise" which i need to get rid of.
again, many thanks!

4. Senior Member
Join Date
Mar 2010
Posts
266
Rep Power
5
wow, your images look a lot worse than i thought :)

you could try to smoothen them a bit - calculate color of each pixel so it takes into account its neighbors (kind of what i was talking about above), then plot it - you'll get shades of gray, darker where the pixels are dense and lighter in other areas - then you could perhaps identify the dark "ridges" and try to make lines out of those... sounds like a hard problem though, good luck!

5. Member
Join Date
Mar 2010
Posts
6
Rep Power
0
It's not a bad idea. I'm not sure but maybe i could do something like that..