Color Quantizer
Eight colors can fix a pixelated mess — and give you a palette worth stealing
- image
- quantized_image
- color_palette
Color Quantizer reduces an image to 2, 4, 8, or 16 colors. On paper that sounds like you're destroying information; in practice it's one of the best cheap fixes for pixelated diagrams, banding, and color noise. When a generated graphic has millions of muddy intermediate colors, reducing it to a handful of dominant ones makes it look intentional - flat poster colors instead of a smear. And as a bonus it hands you the palette itself as an image output, which is genuinely handy when you're building a style guide or a material swatch for a workflow.
How it works
It finds the num_colors dominant colors in the image, then maps every pixel to its nearest palette color. The knobs that matter:
num_colors- 2, 4, 8 (default), or 16. Fewer colors = flatter, more posterized. Start at 8.quantization_method-kmeans,median_cut,most_frequent, orkmeans_minibatch.kmeansis the default and the best quality-for-size tradeoff;kmeans_minibatchis noticeably faster on big images with slightly rougher palettes;most_frequentis dumb and fast;median_cutis the classic quantizer. For a diagram,kmeansrarely disappoints.dithering-noneorfloyd_steinberg. Dithering scatters noise to fake intermediate shades, which is great for photos and terrible for clean flat graphics. For diagrams, leave itnone.color_space- RGB or LAB (default). LAB separates lightness from color, so quantizing in LAB keeps lines crisp and colors true. This is the default for a reason; switch to RGB only if LAB's output feels off.
The optional sample_fraction (default 0.5) limits how many pixels the clustering algorithm looks at - lower it for speed on huge images, and smoothing_iterations (0–5) blurs out speckle in the final result, useful after aggressive dithering or noisy input.
What comes out
Two outputs: quantized_image (the flat poster result) and color_palette (a visualization of the chosen palette that matches the image's dimensions). That palette output is the sleeper feature - wire it to a Preview and you've got an instant swatch you can eyeball without digging through the image.
Where it fits
Use it before the pack's cleanup nodes: quantize → Extract Black or Non-White to Black → LineDetector gives you much cleaner line detection on noisy source, because the background is now a single flat color instead of 300 shades of off-white. For pixel-art-upscale workflows it's a standard pre-step, and for anything going to print or engraving, flat colors are what the machinery expects.
Install
Part of ComfyUI-HappNodeSet by mikemojen. Manager: search HappNodeSet. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/mikemojen/ComfyUI-HappNodeSet.git
pip install -r ComfyUI-HappNodeSet/requirements.txt
Restart ComfyUI. The clustering uses scikit-learn - which is not in the pack's requirements.txt (that lists numpy, opencv-python, scipy, scikit-image, svgwrite, Pillow, torch, cairosvg). If you don't already have scikit-learn installed for another node, expect an ImportError on first run and pip install scikit-learn it. That's the one dependency gotcha in this pack.
Honest take
For photos, this is a toy - real quantization for images belongs to a proper post-processing step, and most_frequent mode will make your landscape look like a budget Game Boy game. But for flat graphics, UI mockups, and diagram cleanup, it's exactly right, and the palette output alone justifies having it installed.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| num_colors | COMBO | 8 | 4 options: 2, 4, 8, 16 |
| quantization_method | COMBO | kmeans | 4 options: kmeans, median_cut, most_frequent, kmeans_minibatch |
| dithering | COMBO | none | 2 options: none, floyd_steinberg |
| color_space | COMBO | LAB | 2 options: RGB, LAB |
| sample_fractionopt | FLOAT | 0.50.1–1 | — |
| smoothing_iterationsopt | INT | 00–5 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| quantized_image | IMAGE | — |
| color_palette | IMAGE | — |