Vectorization of lines from image

Hello,

I am trying to vectorize a binary image that consists of lines. Here is a related post but the function is not published or available.

Is there a function for this available or has anyone implemented the remaining gaps?

Best,

Max

Have you tried ImageGraphics?

Hello Rohit,

I have tried ImageGraphics, but it only works for filled areas and gives as a result the outline of the area. However, I want to have a line.

See the problem here:

l = Line[{{0, 0}, {0, 1}, {1, 1}, {0, 0}}];
Graphics[l, ImageSize -> 300]
Show[ImageGraphics[Rasterize[Graphics[l, ImageSize -> 100]]], ImageSize -> 300]
Show[ImageGraphics[Rasterize[Graphics[{Thickness[0.05], l}, ImageSize -> 100]]], ImageSize -> 300]

Max

Have you tried ImageLines?

Hi Gianluca,

oh I forgot to mention that there are curved lines too in my images.

l = {Line[{{0, 0}, {0, 1}, {1, 1}, {0, 0}}], Circle[{0.5, 0.5}, 0.5]};
i = Graphics[l, ImageSize -> 300]
Show[ImageGraphics[Rasterize[Graphics[l, ImageSize -> 100]]], ImageSize -> 300]
Show[ImageGraphics[Rasterize[Graphics[{Thickness[0.05], l}, ImageSize -> 100]]], ImageSize -> 300]
HighlightImage[i, ImageLines[ColorNegate[i], 1/3]]
HighlightImage[i, ImageLines[ColorNegate[i], 1/15]]

ImageLines only works for straight line segments, but I want a vectorization of the whole image.

Max

Hi Max,

ImageGraphics is not capable of correctly detecting and representing lines and curves. For now, there is this example under possible issues:

In the future, we plan to improve/extend the function to be able to understand and better vectorize 1D shapes.

– Shadi