DY Image Palette
Extract a sorted color list — but only from quantized images
- image
- COLOR_PALETTE
DY Image Palette reads an image and hands you back its colors as a sorted list - most frequent first. It's the pack's color-analysis node, and it's the one that will throw an error the first time you use it if you don't read this first. There's exactly one input, one output, and one rule you have to respect.
That rule: the image can have at most 256 unique colors. It's not a soft guideline, it's a hard ceiling enforced by the code. The node calls Pillow's getcolors(maxcolors=256), which returns None when an image has more colors than the limit - and the node then errors out. A generated photo at 1024×1024 has hundreds of thousands of unique colors. So feeding it a raw render fails, every time, until you've quantized it first.
Fun detail if you ever see the error: the intended message ("Image has more than 256 colors") references a variable the code never defines, so what actually surfaces is a generic RuntimeError: Color extraction failed. It's a small bug in this version of the pack, and the failure is still unambiguous - the node just refuses flat out.
That's not a bug, it's the design: the intended pipeline is DYImageQuantize → DYImagePalette → DYImageMasks. Quantize smashes the photo down to 8–256 colors, Palette reads those exact colors out, and Masks turns each one into its own mask. If you're using Palette on its own, remember you're really using it as a bridge between those two.
How it works
The source is short and honest: convert the tensor to a PIL image, call getcolors(maxcolors=256), throw away the pixel-counts, then sort the RGB tuples by how many pixels use them - most frequent first. So the palette you get isn't a nice balanced swatch; it's a frequency-ranked histogram of what's actually in the image. Your sky color comes first, a stray highlight comes last. That ordering is exactly what you want before the mask step, because the most common colors produce the biggest, most useful masks.
What comes out
The output type is COLOR_PALETTE - a list of RGB tuples. Here's the gotcha that surprises people: that type only exists inside this pack. Nothing in core ComfyUI speaks COLOR_PALETTE, so you can't wire it into a color picker or a style-transfer node. The only consumer is this pack's DYImageMasks. It's a pack-internal data type, full stop. If you want a palette in a format the rest of the ecosystem understands, you'll need a different tool (or you'll accept that this node feeds the pack's own pipeline).
Install
Part of dymokomi/comfyui_dygen (Dy Mokomi, MIT). ComfyUI Manager → search "comfyui_dygen", or:
cd ComfyUI/custom_nodes
git clone https://github.com/dymokomi/comfyui_dygen
Restart. No dependencies beyond what ComfyUI already ships, no model downloads.
Troubleshooting
- Node errors out on any normal render - that's the 256-color ceiling; you skipped the quantize step. Drop a DYImageQuantize before this node and set
colorsto something sane (16–64 is plenty for a palette). - Palette seems short - a flat image genuinely has few unique colors; that's correct.
- Colors look off from the source - they're the exact pixels, just sorted by frequency, so minor colors land at the bottom.
Use it as the middle of the pack's color pipeline and it's frictionless. Use it on a raw render and it'll refuse - which, honestly, is the clearest error message in the whole pack.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| COLOR_PALETTE | COLOR_PALETTE | — |