Nodes/petty-paint-comfyui-node/PettyPaintImageColorsToMasks
ComfyUI Node

PettyPaintImageColorsToMasks

Select every region in a palette at once

By mephisto83·Created 2 years ago·Updated 2 years ago· 3
PettyPaintImageColorsToMasks
  • image
  • MASK
colors#ffffff

The sibling node PettyImageImageColorToMask selects one color; PettyPaintImageColorsToMasks selects a whole list. Feed it an image and several hex colors, and it returns one mask per color, batched together - white where pixels match that color, black elsewhere. If you're working from flat-color segmentation images - a palette render, a color-coded map, a sprite sheet, a mockup where each region is a distinct fill - this turns "select the whole palette" into a single pass instead of a node per color.

The mechanism is the same exact-match pack trick as its single-color sibling: the image is rounded to 8-bit RGB, each pixel's channels get packed into one integer, and each color in your list is compared for strict equality. Every color in the list produces a mask, and the masks come back as a batch - so if your workflow treats a batch of masks as "one per region," you can generate all your regional masks in one go and let a batch-aware consumer (like the pack's PettyPaintConditioningSetMaskAndCombine, which pairs masks with conditionings by index) chew through them.

The inputs and outputs

  • image - the IMAGE to scan.
  • colors - a STRING holding your hex colors, default #ffffff, rendered as a color picker. It's forceInput, so you're expected to wire it - usually from a text node where you can list several values - rather than type a single color. One color works fine too; the list is what makes this node worth using over the single-color one.
  • Output: MASK - a list of masks, one per color, in the order you listed them.

Installing it

It's in the petty-paint pack:

cd ComfyUI/custom_nodes
git clone https://github.com/mephisto83/petty-paint-comfyui-node

Restart ComfyUI, or install via ComfyUI Manager searching "petty-paint-comfyui-node". Declared dependency: Flask==2.1.2, unused here.

Common issues

The exact-match behavior is the thing to respect: these masks have no tolerance, so anti-aliased edges and color drift from resizing will leave holes or kill a whole region. Keep your source flat and keep it away from any node that changes RGB values between your reference color and this node. And mind the batch output - a single mask is still returned inside a list, so nodes expecting a one-off mask tensor will need an index or a batch-aware consumer. For flat-color segmentation, though, this is genuinely the most convenient color-to-mask tool in the pack - it's the one you'd actually reach for over doing it color by color.

CategoryPettyPaint

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
colorsSTRING#ffffff

Outputs (1)

NameTypeDescription
MASKMASK