Image Quantize
The silent partner that makes every vector trace come out clean
- image
- IMAGE
This is the boring node in the pack, and it's the one I'd tell you not to skip. TS_ImageQuantize reduces the number of colors in an image before you trace it - and that single step is what separates a clean, small SVG from a bloated, muddy one.
The idea: vector tracers are literal. If your source has thousands of subtly different shades, the tracer will faithfully carve a shape for every one of them, and your "vector" file comes out heavier than the PNG you started with. Quantize first, collapse the palette to a handful of real colors, and the tracer suddenly sees clean regions with sharp boundaries - which is exactly what tracing wants.
Inputs and output
- image - any IMAGE tensor. It's a filter, so it sits between your generator and the converter.
- colors - 2 to 256, default 16. This is your whole control surface. For flat design and icons, 8–16 is plenty; the fewer colors, the smaller the eventual SVG.
- dither -
Clear(no dithering) orSmooth(Floyd–Steinberg). The names map to a real choice: dithering spreads error across neighboring pixels so bands look smoother in pixels, but it adds noise that a tracer will then faithfully trace. For vector work,Clearalmost always gives the cleaner result. Smooth only helps if you're using the quantized image for something that stays pixel-based.
Output is an IMAGE, ready to feed straight into TS_ImageToSVGStringColor_Vtracer (or the BW node, though quantization matters less there since it's already thresholded to two tones).
How it works
It's a thin wrapper over PIL's built-in quantization: each frame converts to RGB, runs Image.quantize(colors=..., dither=...), converts back to RGB, and returns a tensor. Nothing exotic, no models, CPU-only. The whole thing is under fifty lines.
Why you should actually use it
Every "why is my color trace garbage" thread eventually lands on the same answer: the source had too many colors. Stick this node in front of the color converter and the same settings that gave you mush now give you a clean layered SVG. It's also handy on its own for a retro poster effect - 8 colors, no dither, and a generated image suddenly looks like a print.
Install
It ships with the pack. ComfyUI Manager → search ComfyUI-ToSVG → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Yanick112/ComfyUI-ToSVG/
cd ComfyUI-ToSVG
pip install -r requirements.txt
Requirements are vtracer, numpy, Pillow, torch, PyMuPDF, and potracer. It'll show up under 💎TOSVG/Tools alongside the other utility nodes. No model downloads, no keys, no GPU - a pure CPU filter you can drop anywhere in a graph.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| colors | INT | 162–256 | — |
| dither | COMBO | Clear | 2 options: Clear, Smooth |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |