Nodes/ComfyUI-ZML-Image/ZML_颜色到遮罩
ComfyUI Node

ZML_颜色到遮罩

Turn 'pixels that are green' into a mask you can inpaint with

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_颜色到遮罩
  • 图像
  • 遮罩1
  • 遮罩2
  • 遮罩3
颜色代码1#FF0000
颜色代码2#00FF00
颜色代码3#0000FF
容差10

The fastest way to get a mask is often not a model at all - it's a color. Chroma-key out the green screen, pull the red areas out of a labeled image, isolate the blue marker strokes you drew over a photo. ZML_ColorToMask (ZML_颜色到遮罩) turns any pixels within a tolerance of a target color into a mask, and it does it for three colors at once, so one pass can produce three separate masks.

What it is

A color-key mask extractor from ComfyUI-ZML-Image's mask section. The inputs:

  • 图像 (IMAGE) - the source.
  • 颜色代码1 / 颜色代码2 / 颜色代码3 (STRING, defaults #FF0000 red, #00FF00 green, #0000FF blue) - up to three target colors. Each gets its own color-picker widget on the node, like the pack's standalone picker.
  • 容差 (INT, 0–255, default 10) - how close a pixel has to be to count. 10 is tight; bump it to 40–60 when your green screen has gradient shadows and noise.

Outputs:

  • 遮罩1 / 遮罩2 / 遮罩3 (MASK) - one binary mask per target color.

How it works

It's the classic chroma-key primitive: for each target hex color, the node computes the per-pixel color distance and builds a binary mask from everything within 容差, converted to a float tensor (0 to 1) for ComfyUI's MASK type. No model, no inference - deterministic and instant on a batch. This is the same "get the mask in so many ways" idea the detection layer leans on: a color-key mask is often all you need to drive an inpainting region, especially when you control the source (a green background you added, a color-labeled render, brush strokes in a solid color). Wire the mask to a masked inpainting node or an auto-detailer and the "detect" step of the loop is just this.

Install and gotchas

Standard pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image

or ComfyUI Manager → ComfyUI-ZML-Image, restart. No models.

The gotchas are the usual color-key ones. Tolerance too low and shadows/noise create holes in the mask; too high and it starts swallowing near-colors (skin against a pink backdrop is a classic fail). The masks are per-color, so overlapping targets - red and orange - will bleed into each other's masks, and there's no smoothing, so expect hard edges that need a blur if your inpaint chain wants soft masks. Also remember the pipeline reality: ComfyUI embeds the workflow in saved PNGs, so a "green screen" you add with a background node is recoverable - which is a feature, not a bug, unless you're trying to hide something. Chinese-first UI, English patch at github.com/zml-w/ZZZ_ZML_English_Patch, one-person pack, no English community - but this node is one of the more conventional ones in the pack, and the failure modes are pure color-key math.

Categoryimage/ZML_图像/遮罩

Inputs (5)

NameTypeDefaultDescription
图像IMAGE
颜色代码1STRING#FF0000
颜色代码2STRING#00FF00
颜色代码3STRING#0000FF
容差INT100–255

Outputs (3)

NameTypeDescription
遮罩1MASK
遮罩2MASK
遮罩3MASK