Pixel Grid: Enforce Palette
Lock an image to the colors you actually chose
- image
- quantized_image
- hex_palette_out
Enforce Palette is the second half of the Pixel Grid Helpers cleanup equation. Where Quantize (Max Colors) decides the palette for you, this node lets you hand it the palette yourself - a comma-separated string of hex codes - and it snaps every pixel to the nearest color on that list. The output uses only your colors. No exceptions, no sampler improvisation.
If Median Fixer makes blocks solid, this is what makes a piece feel like deliberate pixel art: enforced discipline. Real pixel art has a palette; AI output has whatever the model felt like that run. This node is the difference, and it's the one the author uses to keep a consistent look across every frame of an animation.
Mechanically it's straightforward: parse the hex string, convert to RGB, then for every pixel find the closest palette color by Euclidean distance in RGB space and replace it. One-pass nearest-neighbor matching, fully deterministic. The honest caveat is that "nearest" in raw RGB isn't always nearest to your eye - there's no perceptual color weighting, so you'll occasionally see a hue shift that looks slightly off. Usually acceptable, and it's fixable: pick palette colors that actually live in the image (run Analyze first), or snap the result with one more pass.
Inputs: image, and hex_palette - a multiline STRING, comma-separated, like #FF0000, #00FF00, #0000FF. Outputs: quantized_image (the re-colored result) and hex_palette_out, which just passes your string through so you can chain it downstream or display it.
Gotchas, grounded in the source. An empty palette returns the image unchanged - graceful, but easy to mistake for "it did nothing," so check your string before suspecting the node. And the hex parser is strict: a malformed code like #GG0000 throws mid-execution. Keep it to valid 6-digit hex, comma-separated, no stray text. Newlines are fine, since the field is multiline and it splits on commas.
The highest-leverage move in this entire pack is combining the pieces: run KMeans to build a palette, then Enforce to lock it in. You get the quantizer's smart color choices and the guarantee that the output is 100% on-palette. That two-node flow is the pack's real reason to exist - generate something mushy, quantize it to find the palette, then enforce it for a clean, deliberate result.
Install: same story as every node here. ComfyUI Manager → search "Pixel Grid Helpers" → install, restart, refresh. Or git clone https://github.com/molbal/ComfyUI-PixelGridHelpers.git into custom_nodes. Zero models, zero dependencies - all tensor math, so nothing to download and nothing to fight with.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| hex_palette | STRING | #000000, #FFFFFF | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| quantized_image | IMAGE | — |
| hex_palette_out | STRING | — |