Nodes/comfyui-AGSoft/AGSoft Mask From Color
ComfyUI Node

AGSoft Mask From Color

Turn any solid-color region into a mask — poor man's chroma key

By Art-xmaster·Created 12 months ago·Updated about 8 hours ago· 23
AGSoft Mask From Color
  • image
  • mask_out
  • convert_mask_to_image
target_color0,255,0
tolerance30
invertfalse
devicecpu

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 MASK to feed your inpaint/removal pipeline.
  • convert_mask_to_image - the same mask as a grayscale IMAGE for 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.

CategoryAGSoft/Mask

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
target_colorSTRING0,255,0Целевой цвет в формате R,G,B (например, '0,255,0' для зелёного).
toleranceINT300–255Допустимое отклонение от целевого цвета. Чем выше — тем больше цветов попадает в маску.
invertBOOLEANfalseИнвертирует финальную маску: чёрное становится белым и наоборот.
deviceCOMBOcpuУстройство для вычислений. 'cuda' ускоряет обработку на GPU, но требует совместимой видеокарты.

Outputs (2)

NameTypeDescription
mask_outMASK
convert_mask_to_imageIMAGE