Nodes/ComfyUI-QG-tools/遮罩上色
ComfyUI Node

遮罩上色

Paint a mask a flat colour, so you can actually see it

By live1617·Created 9 days ago·Updated a day ago· 1
遮罩上色
  • image
  • mask
  • color_rgb
  • IMAGE
◄color_name白►

A mask in ComfyUI is a single-channel tensor of floats from 0 to 1. When you preview it, you get a grey image where the difference between "definitely selected" and "nearly selected" is a few shades of grey your eye can't resolve. 遮罩上色 (QG_MaskColorize) paints the masked region a solid colour over your image, which turns mask inspection from a squint into a glance - and it does a second job: burning a flat area into the pixels before an inpaint.

How it works

image and mask in, coloured image out. The mask is thresholded at 0.5 - above that is masked, below is not - and then used as a hard selection between the original pixels and a solid colour layer. Soft edges become hard edges. That's the feature, not an oversight: for eyeballing a mask, a crisp boundary is what you want, and for burning a region flat, a soft gradient of paint is exactly wrong.

Colour comes from color_name, one of six built-ins (黑 白 灰 红 绿 蓝), or from the optional color_rgb wildcard which wins when connected. That input accepts a [R, G, B] triple as either 0–255 integers or 0–1 floats, so a colour node output plugs straight in.

Batches are handled by broadcast, which is the quietly useful part:

  • A single mask with a batch of images gets expanded across every frame - colour every frame with the same region.
  • A mask batch matching the image batch is applied frame by frame, each frame its own region.
  • A mask batch of any other length gets cut to fit, and a length that can't broadcast against the image batch will fail in the tensor math rather than silently doing something clever. Match the counts.

So if you're debugging a video or an animation batch, one mask won't tell you what's happening on frame 40. Feed a matching batch.

Inputs and outputs

  • image (required, IMAGE) - the picture to paint on.
  • mask (required, MASK) - white (>0.5) gets painted, black keeps the original.
  • color_name (required, enum) - one of six colours.
  • color_rgb (optional, wildcard) - a [R, G, B] triple; overrides color_name.
  • Output IMAGE - painted image.

Two uses that come up constantly. First, verification: colour the mask magenta, hang the output off a preview, and any leaked region or missing edge is instantly obvious. Second, pre-filling for inpainting: paint the area a flat mid-grey or a sampled colour so the model starts from a coherent fill instead of from whatever the mask editor left behind. The KB's masking notes make the same point from the other direction - most mask problems aren't model problems, they're mask problems, and you can't fix what you can't see.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/live1617/ComfyUI-QG-tools

Full restart of ComfyUI, then look for [QG-tools] v0.9.2 加载完成 | 节点数 24 in the console. Manager search ComfyUI-QG-Tools where the Registry listing exists. No pip installs: the requirements file is comments only by design, and this node only touches torch.

Ported from ComfyUI_Muye (MIT). Search mask colorize, paint mask or 遮罩上色.

Where people get burned

Thresholding eats the feather. If you built a soft mask with a blur or a gradient, colouring it will show you a hard edge and quietly hide how soft the original was. Don't judge mask softness through this node.

It's a display tool that writes pixels. The output is a real image with colour baked in. If you meant to inspect and then continue with the original, branch before the colourize, not through it.

Six colours gets old. Black on a dark image and white on a bright one are both useless for inspection. Plug a colour node into color_rgb - a saturated cyan or magenta reads against almost anything.

CategoryQG-tools/遮罩

Inputs (4)

NameTypeDefaultDescription
imageIMAGE底图(批次时每帧都上色)
maskMASK遮罩:白色(>0.5)区域涂色,黑色区域保留原图;接单张遮罩时会应用到批次里每一帧
color_nameCOMBO白内置颜色;接了「自定义 RGB」时以它为准
color_rgbopt*可选自定义颜色:接 [R, G, B] 三元组(0-255 或 0-1)

Outputs (1)

NameTypeDescription
IMAGEIMAGE上色后的图像。