How can I trace the edge of a svg file using inkscape without rasterizing the image and re-vectorizing it?


Question

I have an svg file composed of multiple shapes, and I would like to perform edge detection to create a path around the border of the image.

Basically, I want the equivalent of Path --> Trace Bitmap, but for an image that is already a vector image. I tried using that Trace Bitmap already and it does not do anything.

1
4
4/5/2015 1:37:00 AM

Accepted Answer

If they are shapes, select them all, duplicate them, then union them into one shape.

4
4/5/2015 4:43:00 AM

The quickest solution I can think of to trace a path around a clump of shapes is by using the bucket fill tool. First draw a colored box (to constrain the bucket fill) around the shapes, select the box and zoom to selection.

Next, select the bucket fill tool and set its threshold to 10 or more, so you'll have a smooth fill. (Also set the stroke to something large, say 6 pixels and no fill so you can clearly see the result). Click with the bucket fill tool between your box and the group of shapes enter image description here

The resulting bucket fill will also have a border on the edge of your colored box. enter image description here

Just remove the outer shape by selecting the outer shape's nodes with the node tool then deleting them: enter image description here

You can now move the border to the back of the group of shapes, color the stroke or increase its thickness, or give it a fill. Delete the box if you like. enter image description here

If there is a bitmap included in the group of shapes, I would first trace a path with a thick stroke around the bitmap to have a smooth, uniformly colored edge to trace on before doing the bucket fill. enter image description here

This might not be very accurate – notice there are a few rounded corners where they should be sharp. This can be corrected by using the node tool. If I want a more accurate border, I would go with doing a union operation on all vector shapes, including the shape I placed around a bitmap (I might even enlarge the resulting shape by giving it a thick stroke, converting the stroke to paths, breaking apart the path, and keeping only the outer shape as border).


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
^