# Skeletonization / thinning issue

• 04-07-2010, 04:01 PM
tiny
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?
• 04-09-2010, 10:05 PM
iluxa
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
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?
• 04-10-2010, 01:00 AM
tiny
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!
• 04-10-2010, 02:34 AM
iluxa
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!
• 04-10-2010, 09:23 AM
tiny
It's not a bad idea. I'm not sure but maybe i could do something like that..