Color To Mask
Turn a specific RGB color into a mask
- images
- MASK
Color To Mask does exactly what it says: you give it an image and an RGB color, and it hands back a mask marking every pixel that matches that color. It's the chroma-key trick, in a node. If part of your image is a known flat color - a green screen, a solid backdrop, a colored region you painted in deliberately - this is how you turn that color into a selection you can inpaint, composite, or feed to any mask-driven node.
How it works
It walks the image and asks, for each pixel, "is this close enough to the target color?" Close enough is set by a tolerance. Matching pixels become white in the mask, everything else black. That's the entire mechanism - no model, no segmentation AI, just a color distance check. Which is exactly why it's fast and predictable: unlike a smart segmenter, it doesn't guess, so if your target color is clean and consistent, the mask is clean and consistent too.
The inputs that matter
- red / green / blue (0–255 each) - the target color you're keying on. This is the color you want to become the mask.
- threshold (default 10) - how much variation counts as a match. A JPEG "solid" color is never perfectly uniform, so you need some tolerance. Low threshold = only near-exact matches (tight, but may miss edges); high threshold = looser matching (catches more, but may grab colors you didn't mean). Tune this until the mask covers what you want and nothing else.
- invert (default off) - flip the result, so everything except the color becomes the mask. Handy when it's easier to describe the background than the subject.
There's also per_batch (default 16), which controls how many images are processed at once when you feed it a batch (like video frames). It's a throughput/memory dial, not a masking one - bump it down if a big batch runs you out of memory.
The single output is a MASK.
Where it wires in
The output is a standard mask, so it goes anywhere a mask goes. Common patterns: key out a green screen, then composite the subject onto a new background; select a painted-in region for targeted inpainting; or pipe it into Grow Mask With Blur to feather the edge before you use it. That last combo is worth remembering - a raw color mask has hard edges, and a few pixels of grow-and-blur makes it usable for generation.
Installing it
Comes with kijai's KJNodes pack.
- ComfyUI Manager - search KJNodes for ComfyUI, install, restart.
- Manual -
cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, thenpip install -r requirements.txt, and restart.
No dependencies of note - it's plain image math.
Common issues
The threshold is where all your time goes. Set it too tight and the mask has holes and ragged edges because your "solid" color isn't actually one flat value - compression and anti-aliasing see to that. Set it too loose and you start masking similar colors elsewhere in the image. There's no correct number; it depends on how clean your source is. A true green screen keys easily; a photo of a slightly-shadowed wall does not.
Second, remember this is a color matcher, not an object matcher. If your subject and background share a color, no threshold will separate them - you want a real segmentation node (SAM, or a PointsEditor-driven flow) for that. Color To Mask shines when the color genuinely is the boundary.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| invert | BOOLEAN | false | — |
| red | INT | 00–255 | — |
| green | INT | 00–255 | — |
| blue | INT | 00–255 | — |
| threshold | INT | 100–255 | — |
| per_batch | INT | 161–4096 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |