PettyImageImageColorToMask
Turn one exact color into a mask in a single node
- image
- MASK
Color-keyed masking is one of those things you end up hand-rolling with a ColorToMask node and a channel fiddler until you just want a picker. PettyImageImageColorToMask is that picker: give it an image and a hex color, get back a mask that's white where the pixels match and black everywhere else. It's the same idea as ComfyUI's core ColorToMask, but the color comes in as an actual color-picker hex string (#ff0000 style) instead of RGB channels, which is a nicer workflow when you're matching a palette you've already got written down.
How it works
The mechanism is dead simple and worth knowing because it explains the limits. The image is rounded to 8-bit RGB, the three channels get packed into a single integer (red shifted 16 bits, green 8, blue as-is), and every pixel is compared for exact equality against the hex value you picked. Match means 255 in the mask, no match means 0. Because it's exact equality, there's no tolerance slider - a pixel that's 254 instead of 255 is not a match, and anti-aliased edges (which are blends between two colors) will come out as holes unless the edge pixel happens to equal your color.
That makes it a tool for flat-color work: segmentation palettes, UI mockups, flat-vector renders, sprite sheets, color-coded maps. If your source is a photo, this will frustrate you - that's what the pack's PettyPaintControlNetToMasking or a real segmentation model is for.
The inputs and outputs
image- the IMAGE to scan.color- the hex string, default#ffffff, rendered as a color picker in the UI.- Output: a single
MASK, ready for any masking, conditioning, or inpainting input.
Want to select several colors at once? The pack has PettyPaintImageColorsToMasks, which does this for a list of colors and returns one mask per color.
Installing it
It ships in the petty-paint pack:
cd ComfyUI/custom_nodes
git clone https://github.com/mephisto83/petty-paint-comfyui-node
Restart ComfyUI afterwards, or use ComfyUI Manager and search "petty-paint-comfyui-node". The pack's only declared dependency is Flask==2.1.2, which this node never touches.
Common issues
The exact-match behavior is the trap, and it shows up in two ways. First, anti-aliased edges: if you generated or rendered the image, the edges will be blends and the mask will look eroded. Second, color-space drift - if the image has been through any node that touches the RGB values (even a resize with a different filter), your hex color may no longer exist in the image at all, and you'll get an all-black mask. When that happens, check the actual pixel values instead of trusting the hex you typed. For anything with gradients or transparency edges, this node is the wrong tool; keep it to flat, exact colors and it's genuinely one of the cleaner little utilities in the pack.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| color | STRING | #ffffff | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |