3

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!

walthzer
  • 41
  • 1
  • 7
  • 1
    fun problem. simple skeletonization will not be enough, as you can see. it may not even be part of a good solution. hough transform will also be rather useless due to its noisy nature. you should specify the level of fidelity, i.e. do you just need vias/pads and connectivity (i.e. nets), or do you actually want to recover full layout for all traces and pours? please review the scientific literature. I'm sure others worked on the problem of vectorizing pictures/scans of a PCB's copper layers. – Christoph Rackwitz Jan 02 '21 at 13:55
  • @ChristophRackwitz Good point about the fidelity, the full layout is what I'm looking for. I'll take a look at the literature again, never Thought of the job as a vectorization but it indeed is. Thank you! – walthzer Jan 02 '21 at 14:43
  • I think the problem is called "polygonal approximation"? – user202729 Jan 04 '21 at 02:11

1 Answers1

0

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.

  • OP already knows about (skimage.morphology and) skeletonization, which also involves erosion. simple erosion may reduce the thickness but it won't skeletonize. – Christoph Rackwitz Jul 30 '22 at 15:14
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 01 '22 at 21:19