Image to Clean SVG: A Potrace Workflow for Smooth, Noise-Free Paths
Turn a rough bitmap into a clean SVG with Potrace and mkbitmap: thresholding, despeckling with turdsize, curve smoothing with alphamax and anti-aliasing. A reproducible command-line recipe plus the limits of tracing, explained from the official documentation. The limits of tracing are stated plainly.
View 1 referenceAllow the functional cookie to save your likes. Privacy details
What makes an image to clean SVG conversion different from a traced bitmap?
An image to clean SVG workflow should produce smooth vector paths with few stray nodes, not a bitmap embedded in an SVG wrapper. Clean here means the outlines are continuous, small speckles are gone and curves are simplified without losing the intended shape. That is what lets the file scale without jagged edges.
Potrace defines the goal as "transforming a bitmap into a smooth, scalable image." Its official site notes that "the resulting image is not 'jaggy' like a bitmap, but smooth. It can then be rendered at any resolution." A file that merely wraps a PNG in SVG markup gains none of that; it enlarges into the same blurred or pixelated image. Checking the output for path elements rather than a single embedded raster image is the first verification step.
Why use Potrace and mkbitmap instead of a one-click converter?
Potrace and mkbitmap expose the parameters that decide whether a trace is clean: black-and-white cutoff, speckle suppression, corner threshold and curve tolerance. A one-click converter hides those choices, which is fine for simple logos but leaves you stuck when noise or antialiasing ruins the result.
The two tools have distinct jobs. Mkbitmap preprocesses greyscale and color images so tracing behaves better, while Potrace converts the cleaned bitmap into vector paths. The Potrace documentation calls mkbitmap "a program distributed with Potrace which can be used to pre-process the input for better tracing behavior on greyscale and color images." Skipping preprocessing on a photo is the most common reason a trace comes out as a speckled mess.
How do you convert an image to clean SVG from the command line?
Install Potrace, preprocess noisy inputs with mkbitmap, then call Potrace with the SVG backend and tune the algorithm flags. The whole flow is scriptable, which makes it repeatable across a batch of images with the same settings. Keep the settings in a script so a later batch uses identical values.
# 1. Preprocess a greyscale/color image: blur slightly, then threshold
mkbitmap -f 2 -s 2 -t 0.45 source.png -o clean.pbm
# 2. Trace to SVG, dropping speckles and smoothing corners
potrace clean.pbm -b svg -t 4 -a 1.0 -O 0.2 -o output.svg
# 3. Pipe to stdout when integrating with another tool
potrace clean.pbm -b svg -t 4 > output.svg
The -f and -s flags on mkbitmap control filtering and scaling; -t is its threshold. On Potrace, -b svg selects the SVG backend, -t is turdsize, -a is alphamax and -O is curve optimization tolerance. Start with these values, inspect the result, then change one parameter at a time.
What do turdsize and alphamax actually control?
Turdsize suppresses speckles at or below a given area, so raising it removes small isolated blobs created by noise or compression artifacts. Alphamax is the corner threshold: lower values keep corners sharp, higher values round them into curves. Change one at a time so you can see which fixed the problem.
The Potrace usage page documents -t, --turdsize n as "suppress speckles of up to this size (default 2)" and -a, --alphamax n as "corner threshold parameter (default 1)". For a logo that must keep crisp right angles, lower alphamax toward 0.5. For an organic silhouette where corners are really noise, raise it toward 1.3. Turdsize is the first knob to turn when the output contains dozens of tiny floating dots; a value of 4 to 8 often cleans a scan without touching the main shape.
How do you remove a background before tracing?
Make the background uniformly white or transparent before thresholding. Potrace traces dark regions against light, so a colored or textured background becomes part of the shape unless it is neutralized first. A clean silhouette at this stage saves far more time than editing paths later.
Use an image editor or ImageMagick to flatten the image onto white and boost contrast, then let mkbitmap's threshold decide what is foreground. For a logo on a photo, mask or delete the surroundings first; thresholding alone cannot separate a light object from a light wall. The -i or --invert flag in Potrace helps when the subject is lighter than its background. After tracing, open the SVG in a vector editor and confirm no background rectangle was captured.
When should you anti-alias before tracing?
Anti-alias when the source has hard pixel stair-stepping that would otherwise become jagged vector corners. Smoothing the raster edge first lets Potrace fit cleaner curves, especially on diagonal lines and circular outlines. The goal is a smoother source bitmap, not a blurrier final vector.
Mkbitmap handles this with its filtering options, and some Potrace builds offer an explicit anti-alias pass with Gaussian blur and supersampling. The principle is the same: soften the one-bit edge, then re-binarize at a chosen threshold. Do not over-blur, because fine details disappear permanently before tracing starts. Compare a small test crop with and without the filter; if thin strokes survive and diagonal edges look smoother, keep it. If lettering loses serifs or gaps close up, reduce the blur.
What kinds of images trace badly?
Photographs with soft shadows, gradients or many colors trace poorly because vector tracing needs a clear boundary between foreground and background. High-contrast line art, logos, silhouettes and scanned handwriting are the reliable cases. If a human cannot name the boundary, a tracer cannot infer it either.
Potrace's own examples are "scanned data, such as company or university logos, handwritten notes, etc." A family photo has no single threshold that separates subject from background, so the trace becomes a field of blobs. Multi-color artwork is possible but needs repeated traces of separate layers, one per color, assembled manually. If the goal is merely a scalable version of a photo, keeping the raster at higher resolution is more honest than pretending a trace is vector art.
Frequently asked questions
The questions below tackle the practical snags in an image to clean SVG workflow: licensing, color tracing, why a scalable file can still look wrong, and which backend to choose. Each answer is short enough to use while you are mid-conversion and need a quick decision.
Is Potrace free for commercial work?
Potrace is distributed under a dual license with a GPL option and a commercial license for proprietary use. Check the license section of the official site before embedding it in a closed product; command-line use to produce artwork is a different question from shipping the library.
Can Potrace trace color images directly?
No. Its input is a one-bit bitmap, and mkbitmap or another tool prepares greyscale and color images first. Color output requires tracing several thresholded layers and recombining them.
Why does my SVG look identical at every size but still look wrong?
Smooth scaling is not the same as accurate tracing. If the threshold was wrong or noise was not suppressed, the paths faithfully reproduce a bad interpretation of the image. Revisit preprocessing, not the SVG viewer.
Which SVG backend should I use?
Use -b svg for a standard scalable file. --group keeps related paths together and --flat writes the whole image as a single path, which suits cutting machines that expect one continuous outline.
When does an image to clean SVG workflow pay off?
It pays off when the source is high-contrast and the output needs to be editable, scalable or machine-readable: logos, icons, stencils, engraving templates and line drawings. The command-line approach is worth learning because the same settings can be reused across an entire asset set.
The limits are clear. Tracing does not recover detail that was never in the bitmap, and it does not understand photographs. Used within that scope, Potrace and mkbitmap produce predictable, compact SVGs with far less cleanup than a blind one-click conversion.