Nodes/Pixel Grid Helpers/Pixel Grid: Merge Similar Colors
ComfyUI Node

Pixel Grid: Merge Similar Colors

Collapse 47 shades of 'the same' green into one

By molbal·Created 9 months ago·Updated 9 months ago· 3
Pixel Grid: Merge Similar Colors
  • image
  • merged_image
  • hex_palette
threshold0.05

Merge Similar Colors is a cleanup pass for a specific, maddening failure mode: AI pixel art where one logical color shows up as a dozen slightly different shades. You generated something that's supposed to be flat-colored, and the sampler gave you a gradient of near-identical greens where one solid green should be. Median Fixer handles the block-level noise; this node handles the "all these colors are basically the same" problem across the whole image.

Mechanism, straight from the source: it collects the image's unique colors, then merges greedily. It walks the list, and any color within threshold (Euclidean distance in 0–1 RGB space) of an unmerged seed gets averaged together into one color, then remapped. Outputs are merged_image plus the resulting hex_palette string.

The only input that matters is threshold - a float from 0 to 1, default 0.05. In 0–1 RGB terms that's roughly a 13/255 jump: aggressive enough to fold most anti-aliasing fuzz into the nearest real color, gentle enough to leave genuinely different hues alone. Crank it higher and it merges harder; 0 effectively merges nothing (exact duplicates only). This is the knob you'll actually fiddle with - 0.03 if you're being precious about the palette, 0.1 if you want a brutal flatten.

Two source-grounded caveats. First, the merged color is the average of the group, not one of the original shades - so merging can introduce colors that were never in the input. If that bothers you, follow up with Enforce Palette to snap everything back onto a palette you chose. Second, the loop is O(groups × unique colors): on a photographic image with tens of thousands of unique colors it gets genuinely slow. This node wants pixel art as input. The flow the pack is built around is quantize first (KMeans at your target count), then merge to tidy - that keeps the unique-color count small and the merge fast.

Install: same as every node in this pack. ComfyUI Manager → search "Pixel Grid Helpers" → install, restart, refresh the browser. Or git clone https://github.com/molbal/ComfyUI-PixelGridHelpers.git into ComfyUI/custom_nodes. No models, no extra dependencies, MIT-licensed.

CategoryPixel Grid Helpers

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
thresholdFLOAT0.050–1

Outputs (2)

NameTypeDescription
merged_imageIMAGE
hex_paletteSTRING