logoalt Hacker News

Show HN: Txt2plotter – True centerline vectors from Flux.2 for pen plotters

27 pointsby tsanummylast Monday at 9:57 PM7 commentsview on HN

I’ve been working on a project to bridge the gap between AI generation and my AxiDraw, and I think I finally have a workflow that avoids the usual headaches.

If you’ve tried plotting AI-generated images, you probably know the struggle: generic tracing tools (like Potrace) trace the outline of a line, resulting in double-strokes that ruin the look and take twice as long to plot.

What I tried previously:

- Potrace / Inkscape Trace: Great for filled shapes, but results in "hollow" lines for line art.

- Canny Edge Detection: Often too messy; it picks up noise and creates jittery paths.

- Standard SDXL: Struggled with geometric coherence, often breaking lines or hallucinating perspective.

- A bunch of projects that claimed to be txt2svg but which produced extremely poor results, at least for pen plotting. (Chat2SVG, StarVector, OmniSVG, DeepSVG, SVG-VAE, VectorFusion, DiffSketcher, SVGDreamer, SVGDreamer++, NeuralSVG, SVGFusion, VectorWeaver, SwiftSketch, CLIPasso, CLIPDraw, InternSVG)

My Approach:

I ended up writing a Python tool that combines a few specific technologies to get a true "centerline" vector:

1. Prompt Engineering: An LLM rewrites the prompt to enforce a "Technical Drawing" style optimized for the generator.

2. Generation: I'm using Flux.2-dev (4-bit). It seems significantly better than SDXL at maintaining straight lines and coherent geometry.

3. Skeletonization: This is the key part. Instead of tracing contours, I use Lee’s Method (via scikit-image) to erode the image down to a 1-pixel wide skeleton. This recovers the actual stroke path.

4. Graph Conversion: The pixel skeleton is converted into a graph to identify nodes and edges, pruning out small artifacts/noise.

5. Optimization: Finally, I feed it into vpype to merge segments and sort the paths (TSP) so the plotter isn't jumping around constantly.

You can see the results in the examples inside the Github repo.

The project is currently quite barebones, but it produces better results than other options I've tested so I'm publishing it. I'm interested in implementing better pre/post processing, API-based generation, and identifying shapes for cross-hatching.


Comments

c-jiphtoday at 7:39 AM

Yeah using AI to do a first stage pass seems to work well. I did something similar with Nano Banana: https://github.com/c-jiph/bitmap-to-gcode

I didn't actually end up playing with it too much but the problem I found was it's a hard to get a one-size-fits-all prompt. The AI generated images are usually okay but some features aren't great for a plotter or just don't look visually pleasing. It's still better than having to manually mess with the initial image.

hwjtoday at 11:32 AM

> Requirements

> NVIDIA GPU with 24GB VRAM (RTX 3090/4090)

That's a little bit to much for my trusty notebook...

ansctoday at 9:29 AM

Isn't the examples not very telling if you can't see the input too? Results look good, but I don't know what the input / what kind of preprocessing what done on it.

mft_today at 8:51 AM

Very nice - I’ve struggled (and failed) with a similar approach previously.

FLUX.2 can run on a Mac - any thoughts on making this work on Mac? Needing a 24GB NVidia card is limiting…

piebrotoday at 8:36 AM

Cool project! I tackled the same problem a few weeks ago to plot some nice Christmas cards. I will have a look at your skeletonization approach, because I was struggling with that.

In the end I just used potracer and was fine with having double lines for my cards: https://github.com/piebro/personal-plotting-util/blob/main/i...

show 1 reply
joshutoday at 7:15 AM

Neat!