π§ Mask From Color
Chroma-key a mask straight out of an exact RGB value
- image
- MASK
Mask From Color is the blunt, reliable sibling of Mask From Segmentation. Instead of clustering colors and guessing at regions, you tell it exactly which RGB value to key on, and it hands back a mask of every pixel close to that color. It's the right tool when you already know the exact color you're after - a green-screen background, a specific class color from a segmentation map, a UI region you painted by hand - and don't want the fuzziness of automatic clustering.
That "already know the color" condition is doing a lot of work. This node isn't guessing at what's foreground or background the way a segmentation model does - it's pure color matching, which makes it fast, deterministic, and predictable, but only useful when your source image actually has a flat, known color to key on. Feed it a normal photograph and you'll get a mask of "wherever this photo happens to be white-ish," which is rarely what anyone wants. Feed it a ControlNet segmentation preprocessor's output, where you know class N is rendered as a specific fixed RGB triplet, and it's exactly the right tool - faster and more predictable than running Mask From Segmentation's clustering on an image where you already know the palette.
How it works
red, green, blue (each 0β255, defaulting to 255/255/255 - pure white) define the target color. threshold (0β127, default 0) sets how much per-channel wiggle room a pixel gets before it's excluded from the mask - 0 means an exact match only, and higher values widen the net around your target color to catch near-matches.
Inputs and outputs
image, red, green, blue, threshold. Output: MASK.
Installing it
Via ComfyUI Manager, search "ComfyUI Essentials". Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cubiq/ComfyUI_essentials
Restart. Maintenance-only pack since April 2025 - stable, don't expect new features.
Common issues & troubleshooting
Mask comes out matching things you didn't expect. The default target color is pure white (255, 255, 255). If you drop this node in and run it without setting red/green/blue to your actual target, you'll get a mask of any white pixels in the image - a very common "why is this empty" or "why is this wrong" moment.
Mask is spotty or incomplete on a real photo. threshold at 0 requires an exact pixel match, and real-world images almost never have perfectly flat, unblended color - compression artifacts and antialiasing mean even a "solid" colored region has pixel-level variation. Raise threshold a bit before assuming the node is broken; a small amount of tolerance usually fixes it.
Mask is too loose, picking up unrelated colors. You went the other direction - threshold is too high for how visually close your unwanted colors are to the target. Bring it back down until the mask tightens up around just the region you want.
Trying to key more than one color at once. This node only takes a single RGB target per instance - for a segmentation map with several class colors you want individually, run one Mask From Color per color and combine the results downstream (with something like Mask Batch, if you just need them traveling together) rather than expecting one node to key a whole palette at once.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| red | INT | 2550β255 | β |
| green | INT | 2550β255 | β |
| blue | INT | 2550β255 | β |
| threshold | INT | 00β127 | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | β |