遮罩判断丨条件
Know whether you actually have a mask before you feed one downstream
- mask
- has_mask
- mask_flag
- mask_ratio
- mask_info
An empty mask is the quietest way to break a ComfyUI workflow. The sampler runs, the image comes out, and it just ignores the thing you spent ten minutes painting - because the mask you fed it was all zeros, and nobody told you. MaskJudgment exists to be that somebody. It inspects a MASK tensor, tells you whether it actually contains anything, and hands you the numbers to prove it. It's the smallest node in the QING pack's mask family, and one of the most useful when you're automating anything with a detector or a segmentation model that occasionally returns nothing.
How it works
The node converts your mask to a numpy array and counts non-zero pixels. The interesting knob is threshold (a float, default 0.01): it's the fraction of total pixels that must be non-zero for the mask to count as "real." A mask that's 0.5% covered won't pass; one that's 2% covered will. The logic handles the degenerate cases too - a None input, an empty tensor, or a tensor that's all zeros gets reported as "无遮罩对象" (no mask object) rather than crashing.
You get four outputs:
has_mask(BOOLEAN) - the one you'll actually wire somewhere.mask_flag(INT) - 1 if valid, 0 if not.mask_ratio(FLOAT) - the honest catch: this is a pass/fail flag in disguise. It returns 1.0 when the mask passes and 0.0 when it doesn't, not the raw coverage. The real coverage ratio lives inside themask_infostring, along with non-zero pixel counts, the bounding box, and a "sparse / medium / high quality" verdict. Don't feedmask_ratiointo a math node expecting a percentage.mask_info(STRING) - the human-readable report. Route it into a QuickLogPrinter or a text viewer while you debug.
Where you'd reach for it
Wire has_mask into a router (the QING pack has QING_ConditionRouter, or use any boolean switch) and you get real branching: if a face detector found nothing, skip the face-fix pass; if a segmentation mask came back empty, use the unfiltered image. In a batch of 50 images where some have subjects and some don't, this is how you stop wasting sampler steps on nothing. It's also a cheap way to verify a mask from a remote/URL loader before it hits an inpainting node - the mask-only version of the "check your inputs" habit.
Installing it
MaskJudgment ships in the ComfyUI-QING pack. Install it once and you get all ~79 nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py # or: pip install -r requirements.txt
Then restart ComfyUI. ComfyUI Manager also finds it if you search "ComfyUI-QING." Watch the clone URL - the README prints it as GAOSHI-QING in one spot, but the real repo (and what the pack's own git remote points at) is GAO-SHIQING/ComfyUI-QING. The install script pulls Pillow, opencv-python, scipy, scikit-image, cairosvg, and the openai client, so most of it may already be on your machine.
Things to know
The node doesn't care where the mask came from - hand-painted, a detailer's detector, an ImageMaskConverter output - it just reports on the tensor. One trap: threshold semantics are "fraction of all pixels," so a tiny subject in a huge canvas reads as "no mask" even though it's clearly there. Drop threshold toward 0.001 for high-res images with small subjects. And remember it's a judgement node, not a cleanup node - it won't grow, shrink, or repair your mask. If it says sparse, go fix the mask, don't argue with it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| thresholdopt | FLOAT | 0.010–1 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| has_mask | BOOLEAN | — |
| mask_flag | INT | — |
| mask_ratio | FLOAT | — |
| mask_info | STRING | — |