Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Software to turn black and white image into plottable SVG?
3 points by mg on Oct 9, 2022 | hide | past | favorite | 12 comments
Over the coming days, I can use a plotter and would like to plot some of the black and white images I created via AI:

https://twitter.com/illubots/status/1568997960486162432

Which software is the best to turn these into plottable SVG files?

There are two tricky aspects to it:

The pen of the plotter is rather thin. So one line in the image has to be made from multiple lines plotted.

The plotter can not lift the pen. It plots the whole image in one long line. So it would be nice if the software sorts the lines it creates to minimize the lines the plotter creates when going from one part of the image to the next.



Coreldraw ships with a utility to convert bitmaps to vectors.

It has for at least 25 years.

And is currently available as physical non-subscription media.

Good luck.

https://www.coreldraw.com/en/product/coreldraw/?x-vehicle=pp...


What’s your input format? Bitmap? Vector?

Also, are you sure the plotter cannot lift the pen? That’s rather weird for a plotter, sort-of turning it into an Etch A Sketch (https://en.wikipedia.org/wiki/Etch_A_Sketch)

If you have a bitmap, I would hunt for a printer driver for a plotter, and try intercept its output.

Alternatively, look for software that uses turtle graphics to print bitmaps.

A cursory search didn’t find me much, though (large ink-jet printers nowadays are called plotter, and plotter services seem heavily advertised on Google), so both may not easily lead to results.

(About the only thing I found is https://observablehq.com/@ehouais/bitmap-image-to-plotter-sv...)


The input is a bitmap.

Yes, the plotter cannot lift the pen. This is what it looks like:

https://twitter.com/marekgibney/status/1579054642545438721

The solution you linked to is doing hatching. I also found a tool that does this:

https://github.com/plottertools/hatched

I will probably use that for a first try. If I do more plotting, I would hope to find a more intelligent hatching algorithm, which takes the shape of the areas it fills into account. If none extist, I might even write my own.


You might have some luck with OpenCV - it has a variety of edge detection features to turn an image into lines. Someone may have already pulled together a mechanism to turn that output into an SVG.

Making it plottable might be tricky without manual intervention or implementing your own plotting transformation.

3d printer slicing software transforms 3d models down to stacked layers of “plottable” lines, so you might have some luck looking at projects in that space, too.


I can do the conversion into an SVG myself. For example, here is an SVG version of one of the illustrations made from only black paths:

https://www.gibney.org/jonas-illu-as-paths.html

What I don't know is how to turn those filled paths into thin ziggy zaggy lines that fill the path area.


Ah, very nice.

That should reduce the effort needed to something you might be able to make quick work of, yourself, with some thought about how to walk the vectors in a spiral or something like the zigzags.

This website [1] recommends a tool called vpype [2] which might have an option to do what you need or might be able to be tweaked to do what you need.

Apparently vpype makes some trade-offs in exactness of reproduction for better flexibility, but it does claim to try to honor stroke width.

I’d have recommend digging into SuperSlicer’s code, but their algorithm relies on meshes, so it may not translate as readily.

Nonethless, it is worth mentioning that 3d printer slicing software can handle around a dozen or so different patterns. Spirals, rectilinear, star shapes, etc. so you might find inspiration there.

[1] https://www.acrylicode.com/svg-to-gcode-walkthrough/

[2] https://github.com/abey79/vpype


Thanks! From the description on GitHub, vpype looks very good.

I will play around with it.


You’re welcome! I hope it goes well and that you make a Show HN next.


Tried vpype and the hatched plugin now.

Works, but is very basic. It fills black areas with lines without any regard to the shape of the area. The result looks very "rasterized". One could come up with way better algorithms that take the shape of the source into account when filling it with thin lines.

Maybe I'll have to code my own solution.


Well that is unfortunate.

Hopefully vpype is written in a language that you are familiar with and you can make a pull request for an enhancement or two.

Or perhaps there’s a different tool that will help save time.

If not, I’m sure the plotting community would appreciate anything that you come up with.

I’ll try to do some digging later today and let you know if I find anything else, as I’m now curious.



The hard part is not the tracing, but to fill black areas with thin lines.

vpyped hatched works:

https://github.com/plottertools/hatched

But is very basic.

If that is the best that's out there, I am tempted to write my own.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: