Reduce an image to paths defined by a collection of points

Viewed 210

I'm currently trying to represent an image like the one below as a point defined path. Every "trace" should be a separate path. See picture below Picture 1

The thing I'm trying to do right now is using scikit-image and scipy in python to fill up and skeletonize the image. See picture below Picture 2

import os
from skimage import io, img_as_bool
from scipy import ndimage
from skimage.morphology import skeletonize
from skimage.util import invert
from matplotlib import pyplot as plt

filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'traces.png')
traces = io.imread(filename, True)
inverted = invert(traces)
boolimage = img_as_bool(inverted)
image = ndimage.binary_fill_holes(boolimage)
skeleton = skeletonize(image, method='lee')

plt.imshow(skeleton, cmap=plt.cm.gray)
plt.axis('off')
plt.show()

The skeleton however has many curving lines and I currently do not know how to proceed into cleaning it up into straight lines and angles so the lines endpoint can be used to record the paths. I have tried probabilistic Hough transform from scikit to obtain lines but these struggles with the bending nature of the lee skeleton and complete leaves out geometry.

Any help would greatly be appreciated, if you have any completely different ideas or some algorithm names those are also very much welcome!

1 Answers

I had the same problem to solve when I tried to reduce the thickness of letters from a font. I would suggest to take a look at an erosion algorithm (mathematical morphology). The algorithm is typically applied on binary images (two colors present in an image), therefore this is an image processing problem. This article might help a bit.

Related