Nodes/ComfyUI_Mira/Flat Color Quantization
ComfyUI Node

Flat Color Quantization

Flatten an image into clean color regions

By mirabarukaso·Created 2 years ago·Updated 9 days ago· 206
Flat Color Quantization
  • image
  • out_image
n_colors2048
block_size512
temperature2.00
spatial_scale80
sharpen0.0

Flat Color Quantization takes an image and collapses it into flat, clean color regions - the posterized, cel-shaded look where subtle gradients become defined blocks of color. It's genuinely useful for anime/illustration cleanup, for prepping an image with crisp color boundaries, or just for a stylized flat-color effect. It's more considered than a naive "reduce to N colors" posterize, because it factors in spatial coherence, not just the color histogram.

It's a Util/Image node in ComfyUI_Mira, mirabarukaso's utility pack, and it's a port of the author's separate flat_color_quantization project into a ComfyUI node. That lineage matters for one honest reason the author flags up front, covered below.

How it works

Rather than picking a palette purely by frequency, it balances color similarity against spatial position, so neighboring pixels are encouraged to land in the same flat region and you get coherent blocks instead of speckle. Several inputs shape that trade-off. n_colors caps the palette. temperature softens or hardens how decisively pixels get assigned - higher is more decisive. spatial_scale controls how much a pixel's location (versus its color) weighs into which region it joins, which is the knob that decides whether you get large flat areas or fine detail. block_size sets the processing tile size, and sharpen optionally crisps the result.

Inputs and outputs that matter

  • image - the source.
  • n_colors - palette size (2 to 16384, default 2048). Fewer colors, flatter and more stylized.
  • spatial_scale - how strongly position influences region assignment (1 to 300, default 80). This is the main "big flat areas vs. detail" control.
  • temperature - assignment decisiveness (1 to 10, default 2).
  • block_size and sharpen - tile size and optional edge crisping.

The output is out_image, the quantized result.

Installing it

ComfyUI Manager: search ComfyUI_Mira in the Custom Nodes Manager, Install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/mirabarukaso/ComfyUI_Mira.git, then restart ComfyUI. If the pack errors on load, run pip install -r requirements.txt in its folder and restart. No model files.

Common issues

The important one is straight from the author: the ComfyUI result is not identical to running the same settings in the standalone Gradio/console version of the tool. The reason is that ComfyUI's Load Image node converts the image once on the way in, so the pixels the node sees aren't bit-for-bit the original PNG. If you're trying to reproduce a specific reference result, the README gives a concrete recipe to match its "Foxie" sample at 0% difference - n_colors 1024, block_size 512, temperature 3.0, spatial_scale 60, sharpen 0.0 - so use those as a known-good starting point rather than expecting the standalone app's numbers to transfer.

Beyond that, this is a heavier operation than the pack's one-knob adjustments; large images and high n_colors cost time. If the output looks too busy, drop n_colors and lean on spatial_scale to consolidate regions; if it's too blocky, do the reverse. It's a dial-it-in node - expect a few preview passes before it looks right.

CategoryMira/Util/Image

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
n_colorsINT20482–16384
block_sizeINT51264–2048
temperatureFLOAT2.001–10
spatial_scaleINT801–300
sharpenFLOAT0.00–3

Outputs (1)

NameTypeDescription
out_imageIMAGE