Nodes/ComfyUI-QG-tools/Mask Colorize
ComfyUI Node

Mask Colorize

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

By live1617·Created about a month ago·Updated about 7 hours ago· 4
Mask Colorize
  • image
  • mask
  • color_rgb
  • IMAGE
◄color_namewhite►
◄r-1►
◄g-1►
◄b-1►

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/Mask

Inputs (7)

NameTypeDefaultDescription
imageIMAGEThe base image; every frame of a batch is painted.
maskMASKThe mask: white areas (above 0.5) take the color, black areas keep the image. One mask paints every frame; a shorter batch repeats to fill. Must be the same width and height as the image.
color_nameCOMBOwhiteOne of the built-in colors; a wired RGB triple wins over it.
color_rgbopt*Optional custom color, as [R, G, B]. All three at or below 1 means a 0-1 triple; anything else is read as 0-255. Wins over both the picker and the three boxes below.
roptINT-1-1–255Red, 0-255. -1 takes red from the built-in color above. Setting any of R/G/B overrides the picker for that channel.
goptINT-1-1–255Green, 0-255. -1 takes green from the built-in color above.
boptINT-1-1–255Blue, 0-255. -1 takes blue from the built-in color above.

Outputs (1)

NameTypeDescription
IMAGEIMAGEThe image with the masked area painted.