Nodes/ComfyUI/Convert Image Color to Mask
ComfyUI Node Runs on cloud

Convert Image Color to Mask

Chroma key without the greenscreen

By Comfy-Org·Created 4 years ago·Updated about an hour ago· 129,820
Convert Image Color to Mask
  • image
  • MASK
color0

Convert Image Color to Mask turns every pixel that exactly matches one color into white and everything else into black. It's chroma keying without a greenscreen - you name a color, it builds a mask from the pixels that are that color. If you've ever had a flat-color image and wished it were a mask, this is the whole workflow in one node.

Why you'll reach for it

The classic use is pulling a mask out of something that has a flat, unambiguous color region. Think of the outpainting trick that circulates in the community: pad your canvas with a solid red border, prompt the model to "replace the red padding," and then convert that exact red into a mask so you can composite the result. That trick runs on this node. Same idea for keying out a solid-color background, an animated cel, or any generated image with a clean flat region.

It's the blunt instrument of the mask family. For real-world photos, background removal tools (rembg, BiRefNet, SAM) are the right answer - a photo never has an exact flat color to key. But for flat color - synthetic images, UI screenshots, colored-canvas workflows - this is faster, free, and deterministic, with no model to download.

How it works

Each pixel is packed into a single 24-bit integer - red shifted left 16 bits, green left 8, plus blue - and compared against your color value. Exact equality means the pixel becomes 1.0; anything else becomes 0.0. The result is a hard binary mask, no soft edges, no tolerance. Note the packing order: color is 0xRRGGBB, so red is 16711680 (0xFF0000), white is 16777215 (0xFFFFFF), black is 0. The default is 0, which keys out black.

The inputs and outputs

  • image - the source image.
  • color - the 24-bit RGB value to key, as a single integer from 0 to 16777215. Default 0 (black).

One output, MASK.

Getting it

Core ComfyUI, nothing to install. It's in comfy_extras/nodes_mask.py with the rest of the mask family.

Where people get burned

  • Exact match only. There's no tolerance slider. Antialiased edges, JPEG compression, or any gradient mean those pixels won't match and you'll get a ragged key with holes around the edges. This is the number-one surprise. For anything with soft edges, feather the result or switch to a segmentation model.
  • The color format trips people. It's a single packed integer, not "R, G, B" fields. If you're thinking in 0xRRGGBB, you're fine; if you type 255 expecting red, you've asked for a near-black color.
  • It's binary, so pair it. If you need a soft edge after keying - and you almost always do for compositing - chain FeatherMask or a blur on the output. A hard chroma-key mask pasted straight onto a scene is exactly how you get the "glued on" look.
Categoryimage/mask

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
colorINT00–16777215

Outputs (1)

NameTypeDescription
MASKMASK