AGSoft Mask From Color
Turn any solid-color region into a mask — poor man's chroma key
- image
- mask_out
- convert_mask_to_image
You have an image with a big flat green screen, a solid-color product backdrop, or a background that's basically one hue - and you need a mask of everything that isn't it. AGSoft Mask From Color is the cheap chroma-key: give it an image and a target RGB, and it produces a mask of everything within tolerance of that color. It's not magic, it's color distance - but for the right input it saves you a segmentation model.
How it works
The node takes your image, reads the target_color string in R,G,B format (default "0,255,0" - pure green, the classic key color), and computes per-pixel distance from that color. Pixels within tolerance (0–255, default 30) become white; everything else goes black. It's the standard color-matching trick from OpenCV, which the pack already depends on, so no extra installs.
The result comes out twice:
- mask_out - the real
MASKto feed your inpaint/removal pipeline. - convert_mask_to_image - the same mask as a grayscale
IMAGEfor previewing.
Two controls shape the outcome:
- invert (default off) - flips it. With a green backdrop you want the subject masked, not the green, so the usual setup is: target the backdrop color, tick invert, and the subject becomes the mask. Or don't tick it and use the output as a background mask directly.
- device - cpu/cuda, default cpu. A per-pixel distance pass is cheap; leave it.
Where it works (and where it won't)
This is the honest part: color-keying only works when the color you're keying is actually consistent. It's great for flat synthetic backdrops, solid product colors, or UI screenshots. It's bad for real-world photos - lighting gradients, shadows and noise spread the "same" color across hundreds of distinct RGB values, and no tolerance setting will fix that without also swallowing your subject. If your backdrop has texture or lighting falloff, use a real segmentation tool instead and don't fight this node.
When you do use it, the tolerance dial is the whole game. 30 catches a clean flat color. Creep up toward 60–80 if there's mild shading, and watch the preview (that's what convert_mask_to_image is for) - as soon as white bleeds onto your subject, you've gone too far. A little erosion after (the pack's Mask Fix, erode_dilate) cleans up those edge stragglers neatly.
Installing
Same as the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft
Restart ComfyUI, or ComfyUI Manager → "comfyui-AGSoft". No models, no downloads. Remember the color format is R,G,B with no spaces - "0,255,0", not "0, 255, 0" - and that a mistyped color just produces a mask of nothing, which is the most common "why is it empty" report.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_color | STRING | 0,255,0 | Целевой цвет в формате R,G,B (например, '0,255,0' для зелёного). |
| tolerance | INT | 300–255 | Допустимое отклонение от целевого цвета. Чем выше — тем больше цветов попадает в маску. |
| invert | BOOLEAN | false | Инвертирует финальную маску: чёрное становится белым и наоборот. |
| device | COMBO | cpu | Устройство для вычислений. 'cuda' ускоряет обработку на GPU, но требует совместимой видеокарты. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask_out | MASK | — |
| convert_mask_to_image | IMAGE | — |