Nodes/comfyui_dygen/DY Image Quantize
ComfyUI Node

DY Image Quantize

Flat colors, poster looks, and the palette machine this pack is built around

By dymokomi·Created 2 years ago·Updated 2 years ago· 1
DY Image Quantize
  • image
  • IMAGE
colors256
method
kmeans0

DY Image Quantize doesn't look like much: feed it an image, get the same image back with the color count smashed down to whatever number you pick. No model, no API key, no weights download - under the hood it's one Pillow call in a ComfyUI wrapper. It's also the engine room of this pack, because the other color nodes in comfyui_dygen are useless until you've quantized.

Why would you want fewer colors? Three reasons, in rough order of how often people actually use it. First, posterization: drop a portrait or landscape to 8–32 colors and you get that clean, flat, almost screen-printed look that reads as stylized instantly - a fun low-effort effect for photo-to-art experiments. Second, it's the on-ramp to the rest of this pack: DYImagePalette fails on ordinary photos (more on that in its own article), and the fix is to quantize first. Third, legit palette-prep work: if you're building game assets, low-poly collages, or anything with a strict color budget, this is the node.

How it works

One line of Pillow: image.quantize(colors, method, kmeans), wrapped in tensor-to-PIL-to-tensor conversion. The four method options are Pillow's own built-in quantizers, not something this author invented:

  • MEDIANCUT - the classic, good general-purpose default
  • MAXCOVERAGE - biases toward covering the widest spread of colors
  • FASTOCTREE - quick, rougher on smooth gradients
  • LIBIMAGEQUANT - best quality, but only works if your Pillow was compiled with libimagequant support

kmeans (0–100 iterations) refines the palette after the initial pass. 0 means skip it, and you rarely need more than a handful of iterations to see a difference.

Two honest caveats straight from the source. The node only processes the first image of a batch - feed it four images and you get one back. And Pillow caps quantize() at 256 colors, which is exactly where the slider stops. You can't go higher, and you rarely need to.

Inputs you'll actually touch

  • colors - the number of distinct colors you want. 2 gives you a stark two-tone cutout; 256 is basically the original.
  • method - leave on MEDIANCUT until you have a reason.
  • kmeans - leave at 0 until you have a reason.

That's the whole thing. One IMAGE in, one IMAGE out, wire the result into a preview node or keep going down the palette path.

Install

Part of dymokomi/comfyui_dygen (the "DyGen" pack by Dy Mokomi, MIT licensed). Easiest via ComfyUI Manager - search "comfyui_dygen" and install - or the old-school way:

cd ComfyUI/custom_nodes
git clone https://github.com/dymokomi/comfyui_dygen

Restart ComfyUI. That's it: no requirements.txt to satisfy, no models to download. The whole pack runs on Pillow, numpy, and torch, which every ComfyUI install already has.

Troubleshooting

  • LIBIMAGEQUANT errors out - your Pillow build lacks libimagequant. Switch to MEDIANCUT; nobody will notice unless you're chasing last-bit quality.
  • Colors look banded or posterized harder than expected - that's the effect, not a bug. Try MAXCOVERAGE or a higher colors value.
  • Batch disappeared - by design, only the first frame is processed.

Where it fits

This is step one of the pack's signature pipeline: DYImageQuantize → DYImagePalette → DYImageMasks, which turns a generated image into a palette plus a per-color mask set you can reorder, swap, or composite. If you only install one node from this pack, this is the one - everything else builds on a color-reduced image.

CategoryDyGen/effects

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
colorsINT2562–256
methodCOMBO4 options: MEDIANCUT, MAXCOVERAGE, FASTOCTREE, LIBIMAGEQUANT
kmeansINT00–100

Outputs (1)

NameTypeDescription
IMAGEIMAGE