Nodes/ComfyUI PixelArt Detector/🎨PixelArt Palette Generator
ComfyUI Node

🎨PixelArt Palette Generator

Make your own game palette from any image — then reuse it everywhere

By dimtoneff·Created 3 years ago·Updated 10 months ago· 429
🎨PixelArt Palette Generator
  • image
  • image
  • color_palettes
colors16
mode

The Palette Loader gives you other people's palettes. This node makes your own. PixelArtPaletteGenerator looks at any image, picks N colors that best represent it, and outputs two things: a rendered palette image you can preview, and a color_palettes LIST you can feed straight into the Palette Converter's paletteList input. It's the missing link for the workflow that goes "here's a concept piece I like - make everything in this game match its color mood."

How it works

The color extraction uses pyclustering's k-means with a fixed k - k-means over the image's pixels, so the centers it converges on are your palette colors. Then it does something slightly opinionated: it sorts colors by luminance and groups them by which channel is dominant (reds, greens, blues, then everything else). The result is a palette that reads in a sensible order - dark to light within each hue family - instead of a jumble of cluster centers in arbitrary order. "Chart" mode lays the swatches out in a grid; "back_to_back" renders them as a horizontal strip. Each swatch is a 128px cell, so the output image is preview-friendly, not tiny.

The inputs that matter

  • image - any IMAGE tensor. Handles batches: each image gets its own palette, stacked as a batch of palette images.
  • colors - the number of palette colors, 8–256, default 16. That's the sweet spot for retro: NES pushed 25 simultaneous colors, the Game Boy had 4.
  • mode - Chart (grid layout) or back_to_back (horizontal strip).

The outputs

  • image - the rendered palette sheet (IMAGES, one per input image).
  • color_palettes - a LIST in the same {"p": bytes, "a": ...} format the Loader produces, so it drops directly into the Converter's paletteList input. Note the Converter's palette swap uses Image.quantize, so the generated palette's colors get used as-is - it'll be an exact match to the colors you extracted, not an approximation.

The obvious pipeline: generate a palette from a reference image → feed it to the Converter → convert your actual sprites to it. Because it's a LIST, you can also drop it into a Loader's slot if you wire the Loader first - the Converter takes either.

Installing the pack

This node ships in dimtoneff/ComfyUI-PixelArt-Detector. Install via ComfyUI Manager (search "ComfyUI PixelArt Detector") or:

cd ComfyUI/custom_nodes
git clone https://github.com/dimtoneff/ComfyUI-PixelArt-Detector

Restart ComfyUI. Dependencies auto-install on first load (opencv-python, scipy, pyclustering, Pillow, numpy). The pyclustering dependency is worth flagging on every node in this pack: it's pulled from a prebuilt wheel the author hosts, x86_64 only, so Apple Silicon or unusual Python builds may need a manual pip install pyclustering and a restart.

Gotchas

  • k-means is not deterministic. Run it twice on the same image and you can get slightly different palette colors, especially with more colors. If you need a reproducible palette for a game asset pipeline, run it once, save the palette, and reuse the saved list.
  • High color counts on large images are slow. k-means over every pixel with k=256 is real work; downscale the source first if you're generating big palettes.
  • The "a" annotation field on the output is a placeholder ("Arbitrary identifier or annotation") - if you're labeling palettes for the Converter's grid, you'll want to rename it yourself or add the palette to the palettes/1x folder instead.
  • Old node instances in downloaded workflows don't update cleanly - delete and re-add from the Image/PixelArt menu.
Categoryimage/PixelArt🕹️

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
colorsINT168–256
modeCOMBO2 options: Chart, back_to_back

Outputs (2)

NameTypeDescription
imageIMAGE
color_palettesLIST