Nodes/ComfyUI-SmartImageTools/Smart Image Palette Convert
ComfyUI Node

Smart Image Palette Convert

Photoshop-style indexed color, local and free

By slvslvslv·Created about a year ago·Updated 25 days ago· 2
Smart Image Palette Convert
  • image
  • reference_image
  • additional_colors
  • image
  • palette
num_colors8
dithering_amount1.00
algorithmHybrid Lab/RGB K-Means

Remember Photoshop's "Indexed Color" mode - the thing that turns a photo into a limited set of colors with dithering, the look that screams retro posters and pixel art? Smart Image Palette Convert is that, as a ComfyUI node, done properly in CIELAB color space. If you've ever wanted a deliberate, limited-palette look on top of a generated image - or to match a piece of art to a fixed swatch set - this is the node.

How it works

It runs K-means clustering on the image's pixels to find the optimal color centers, then maps every pixel to its nearest palette color. The quality comes from the details:

  • LAB color space. The default "Hybrid Lab/RGB K-Means" works in perceptual Lab space, where color distance matches how humans actually see it, instead of naive RGB distance. There's also a pure Perceptual (Lab), a straight K-Means (RGB), and Selective (fast median-cut style).
  • Floyd-Steinberg dithering with an adjustable dithering_amount (0–1) - Numba-compiled, so the error-diffusion pass stays fast even on big images.
  • Palette control. Optionally wire a reference_image and the palette is extracted from that image instead of your input - so you can force your picture into another image's color scheme. additional_colors lets you inject extra colors into the computed palette.
  • Transparency is preserved, and the palette is sorted sensibly (hue, then luminance, then saturation) so the output swatch reads like a real palette, not a random dump.

Inputs and outputs

  • image - the image to convert.
  • num_colors - palette size, 2–256 (default 8).
  • dithering_amount - 0 to 1 (default 1).
  • algorithm - one of the four above.
  • reference_image, additional_colors (optional) - palette sources.

Outputs: image (the posterized result) and palette (a 1-pixel-high strip of the palette used, ready to preview).

Installing it

From the ComfyUI-SmartImageTools pack:

cd ComfyUI/custom_nodes
git clone https://github.com/slvslvslv/ComfyUI-SmartImageTools
pip install -r ComfyUI-SmartImageTools/requirements.txt

Restart ComfyUI, or use ComfyUI Manager. This node is the reason scikit-learn and scikit-image are in the pack's requirements - no models, no downloads, but the K-means and Lab conversion need those libraries.

Where it shines

Posterized styles, retro/pixel art aesthetics, and palette-matching between images are the sweet spot. A few tips from actual use: low num_colors (4–8) with dithering_amount around 0.3–0.6 gives the classic printed-poster dither instead of hard banding; the palette output is worth previewing so you know exactly what you're committing to. It's CPU-based K-means, so on 4K images keep num_colors reasonable or the clustering step will take a moment.

CategorySmartImageTools

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
num_colorsINT82–256
dithering_amountFLOAT1.000–1
algorithmCOMBOHybrid Lab/RGB K-Means4 options: Hybrid Lab/RGB K-Means, Perceptual (Lab), K-Means (RGB), Selective
reference_imageoptIMAGE
additional_colorsoptIMAGE

Outputs (2)

NameTypeDescription
imageIMAGE
paletteIMAGE