ComfyUI Node

Check Mask (UTK)

Is this mask actually covering anything? Now you can ask

By whmc76·Created about a year ago·Updated about a month ago· 72
Check Mask (UTK)
  • mask
  • bool
white_point1
area_percent1

Empty and broken masks are the silent killers of automated workflows. A detection node returns nothing, the mask comes back all black, and your conditional inpainting either runs on nothing or refuses to run at all - and you can't tell which. Check Mask (UTK) answers the one question that matters: does this mask cover a meaningful amount of the image? It returns a boolean you can feed into a switch, so your workflow can make decisions instead of guessing.

How it works

Give it a mask and it computes the percentage of pixels above a brightness threshold - that is, the fraction of the mask that's "white" (covered). Then it compares that fraction against your area_percent requirement.

  • white_point (default 1) - the pixel value that counts as "covered." Masks are 0–255 grayscale; 1 means "anything above pure black counts," which is the right setting for binary masks. If your masks are soft and slightly noisy, raise it to skip faint dust.
  • area_percent (default 1) - the minimum coverage to pass. "At least 1% of the image must be masked, or I call it empty." Bump it to 5–10% if you want to ignore tiny stray specks.

The node also downscales very large masks before measuring (above ~512², it resizes to a 512-wide thumbnail), so the check is fast even on 4K inputs - it's measuring statistics, not doing pixel surgery.

One output: bool - True if the mask covers enough, False if it's empty or too sparse.

Where it fits

The natural partner is a lazy switch (the pack's LazySwitchKJ_UTK is a perfect match): wire Check Mask's bool into the switch, have the on_true branch run your inpainting and on_false pass the original through. Result: the expensive fix only fires when there's actually something to fix, and empty detections stop breaking the chain.

It also catches the "mask loaded wrong" failure early - if a workflow suddenly produces no output and this node is saying False, your mask is the problem, not the sampler.

Installing it

Standard pack install - ComfyUI Manager → search ComfyUI-UniversalToolkit, or:

cd ComfyUI/custom_nodes
git clone https://github.com/whmc76/ComfyUI-UniversalToolkit
cd ComfyUI-UniversalToolkit && pip install -r requirements.txt

Then restart. Uses OpenCV/PIL, both in the pack's requirements.

Gotchas

  • A None mask returns False with a warning - handled gracefully, which is exactly what you want from a guard node.
  • It checks the first frame of a batch. If your mask batch has ten frames, only frame 0 is measured. For video masks, check per-frame upstream if you need per-frame decisions.
  • The percentage is of the whole image. A small face on a big canvas might legitimately be under 1% - tune area_percent down for wide shots or your guard will veto valid crops.

It's a tiny guard node, but it's the kind of thing that turns a fragile conditional workflow into one you can trust overnight. Pair it with a lazy switch and you've got the simplest reliable "only fix when needed" pattern in ComfyUI.

CategoryUniversalToolkit/Image

Inputs (3)

NameTypeDefaultDescription
maskMASK
white_pointINT11–254
area_percentINT11–99

Outputs (1)

NameTypeDescription
boolBOOLEAN