Color To Mask (UTK)
Turn 'this color' into a mask
- images
- mask
Need a mask of everything green in an image? Classic chroma-key territory, and you don't need a segmentation model to get it. Color To Mask (UTK) converts a chosen RGB color into a mask based on color distance - every pixel within a threshold of your target color becomes white, everything else black. It's the numbers-only version of "select by color," and it's perfect for solid-color backgrounds, logo extraction, or building quick masks from flat scenes.
How it works
You pick a target color with the red / green / blue inputs (each 0–255). The node computes the Euclidean distance between every pixel's color and your target, and pixels within threshold (default 10) of that distance are included in the mask. Lower threshold = tighter match, higher = catches similar shades.
Two controls shape the result:
- invert (default off) - flip the mask so everything except the matching color is white. That's your "select the subject, not the background" mode, and it's where this node earns most of its keep.
- per_batch (default 16) - how many images process at once when you feed a batch. It's a memory/efficiency dial for batch jobs; the tooltip spells it out as the batching control.
One output: mask, in the same dimensions as the input batch.
Where it's actually good
- Solid backgrounds - a flat blue or green screen converts to a near-perfect mask with the right threshold.
- Quick subject extraction - pick the background color, invert, and you have a rough cutout without loading a background-removal model.
- Batch cleanup - dozens of product shots on the same backdrop; one color picker value handles them all.
The honest limit: it's color-distance, not understanding. Gradients, shadows, and backgrounds that bleed into the subject will produce ragged edges. For anything with a real backdrop you'll still want a proper segmentation model (the KB's background-removal notes cover those). But for flat-color work this is instant, deterministic, and free.
Installing it
Standard pack install - ComfyUI Manager → search ComfyUI-UniversalToolkit, or:
cd ComfyUI/custom_nodes
git clone https://github.com/whmc76/ComfyUI-UniversalToolkit
cd ComfyUI-UniversalToolkit && pip install -r requirements.txt
Then restart. Torch-only, nothing extra.
Gotchas
- Default threshold 10 is tight. Real-world "white" backgrounds aren't pure white - they're #FAFAFA with gradient light. Expect to raise the threshold to 30–60, and adjust per image rather than trusting one magic number.
- Invert is your friend but check the output - inverting a noisy match inverts the noise too. Feather or clean the mask downstream if edges look speckled.
- JPEG compression wrecks flat colors. If your source is a compressed image, the "flat" background isn't flat anymore; you'll be chasing threshold values. Try to source lossless when you can.
For a quick-and-dirty select-by-color, it's the most direct tool in this pack. Just don't ask it to do segmentation's job on a busy scene - it'll hand you back a mask of the whole world's similar colors.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | Input images to convert to masks | |
| red | INT | 00–255 | Red component of target color |
| green | INT | 00–255 | Green component of target color |
| blue | INT | 00–255 | Blue component of target color |
| threshold | INT | 100–255 | Maximum color distance for inclusion in mask |
| invert | BOOLEAN | false | Invert the mask (exclude matching colors) |
| per_batch | INT | 161–4096 | Number of images to process simultaneously |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |