Nodes/ComfyUI_KimNodes/🍒Mask_White_Area_Ratio📊蒙版白色区域占比
ComfyUI Node

🍒Mask_White_Area_Ratio📊蒙版白色区域占比

Is your mask mostly empty? This node turns it into a yes/no

By wjl0313·Created 2 years ago·Updated 12 months ago· 54
🍒Mask_White_Area_Ratio📊蒙版白色区域占比
  • mask
  • white_area_ratio
  • boolean
area_threshold50

Every time you generate with a mask you end up asking the same question: is there actually anything in there? Mask_White_Area_Ratio answers it twice - once as a number, once as a decision.

It takes any MASK and does two things. First it computes what fraction of the frame counts as "white" - that's your foreground, the area you care about. Second, it compares that fraction against a threshold you set and hands you a clean BOOLEAN. In one node you get "42% of the mask is white" and "yes, that's over my cutoff."

That boolean is the part that makes it useful. Wire it into a switch, a conditional route, or a filter and your workflow starts making decisions instead of you eyeballing every output. The typical use: batch generation where a mask-based branch (segmentation, inpainting masks, background removal) sometimes produces an empty or near-empty mask, and you only want to keep or process the frames where the subject actually fills the frame. It's the same gate you'd otherwise build with a bunch of math nodes, minus the math nodes.

The mechanism. For each frame in the mask batch it binarizes the mask - anything above 0.5 counts as white (that's the author's stated standard, and it's baked in rather than exposed) - then divides white pixels by total pixels. That gives white_area_ratio, a FLOAT between 0 and 1. It then compares ratio * 100 against area_threshold and produces the boolean.

Inputs that matter. There are really only two, and one of them is the whole node:

  • mask - the MASK you're interrogating.
  • area_threshold - a FLOAT defaulting to 50, range 0–100. This is the percentage cutoff. 50 means "flag true when more than half the mask is white."

Outputs. white_area_ratio (the 0–1 float, per frame) and boolean (whether that ratio beats the threshold).

Where people get burned: the units. The output ratio is 0–1 but the threshold is 0–100, so setting area_threshold to 0.5 is not half - it's half a percent, and the node will almost always say true. Set 50 for "at least half." The node is also per-batch-frame: feed it a 4-image mask batch and you get back a list of four ratios and four booleans, not a single verdict, which is exactly what you want when gating a batch but a surprise if you expected one answer.

Install. It ships in the KimNodes toolbox (author wjl0313, a Chinese-language utility pack on the Comfy registry). ComfyUI Manager → search "ComfyUI_KimNodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/wjl0313/ComfyUI_KimNodes

then restart ComfyUI. This node itself is pure PyTorch - no model downloads, no heavy dependencies - so it's the friendly corner of the pack.

Troubleshooting. If the boolean never flips, check your threshold units first (see above). If you're feeding it a mask that came out of a segmentation model with soft edges, remember the 0.5 cutoff means faint halos don't count as white - that's usually a feature. And the node expects a proper MASK tensor; a stray IMAGE on the input will just error out, so wire from mask-producing nodes (segment anything, BiRefNet, or ComfyUI's own MaskFromColor) rather than an image output.

Category🍒 Kim-Nodes/🔲Mask_Tools | 蒙板工具

Inputs (2)

NameTypeDefaultDescription
maskMASK
area_thresholdFLOAT500–100

Outputs (2)

NameTypeDescription
white_area_ratioFLOAT
booleanBOOLEAN