
Sketch Vectorization
Convert hand-drawn sketches into SVGs using deep learning and Bézier curve fitting.
About this notebook
This notebook converts a photograph of a hand-drawn sketch into an SVG image made of a few Bezier curves. It reimplements the paper "Fidelity vs. Simplicity: a Global Approach to Line Drawing Vectorization" with the sketchy-svg library, together with matplotlib, NumPy, SciPy, and scikit-image. A butterfly sketch from the repository is the running example.
Each stage of the pipeline appears as a matplotlib plot. A convolutional network predicts a black-and-white mask, and erosion measures the stroke thickness. scikit-image reduces the mask to a one-pixel skeleton, and a graph traversal extracts chains of pixels. A linear least-squares fit converts each chain into a cubic Bezier curve. An optimizer then perturbs the curve network at a decreasing temperature to balance fidelity against simplicity. marimo progress bars track the optimization, and an anywidget player replays every perturbation.
The mask model is a network trained on the MMSVG-Icon dataset with synthetic noise, and it runs through ONNX, so it needs no GPU. The notebook also runs in the browser: in a WASM environment it patches onnxruntime and loads the sample images from GitHub instead of local files. A gallery at the end applies the full pipeline to more sketches, CAD drawings, and figures from the paper.











