Mask Area Percentage v5.1.0
Is that mask actually covering anything?
- image
- percentage
- white_pixels
- total_pixels
Mask Area Percentage answers the most underrated question in any mask-based workflow: how much of this image is actually white? It takes an image, thresholds it at a value you choose, and reports three numbers - the percentage of above-threshold pixels, the raw white-pixel count, and the total pixel count. That's the entire node, and it's more useful than it sounds.
The mechanism is one OpenCV pass: grayscale conversion, cv2.threshold at your threshold value, countNonZero, and a percentage. Nothing clever, which is the point - it's a cheap, deterministic measurement you can hang a whole conditional branch on.
Inputs
image- the mask or binary image to measure.threshold- default 127, range 0–255. The cutoff for "white." A mask that's already 0/255 can use any value between; a soft mask lets you tune what counts as covered.
Outputs
percentage- FLOAT, percent of pixels above threshold (0–100).white_pixels- INT count.total_pixels- INT, the denominator.
Why you'll actually reach for it
Two classic jobs. Validation: segmentation masks come out wrong all the time - empty, all-white, or covering half the frame. Feed the mask to this node, compare the percentage to a sanity range with a compare node, and skip or retry anything outside it before it pollutes the pipeline. An "is this mask plausible?" check saves real time in batches. Auto-tuning: when a threshold or segmentation parameter needs adjusting per image, the coverage percentage is a natural signal - too low means under-segmentation, too high means bleed. You can wire the percentage straight into a loop that nudges the parameter.
Install and gotchas
Same pack, same routine:
cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
# restart ComfyUI
Or via ComfyUI Manager, search "tri3d." Keep the folder named tri3d-comfyui-nodes. OpenCV only - no model, no extra deps, instant even on CPU.
- It measures every white pixel, not connected regions. A mask with ten small specks scattered across the frame can report the same percentage as one solid blob - if you care about "is this one region," that's a connected-components job, not this node.
- It works on the image as fed. If you're measuring a MASK tensor, convert it to IMAGE first or grab the channel you mean; it converts RGB to grayscale but expects an IMAGE-type input.
- It reads the first frame of a batch (
[0]). Measure one image at a time.
For a utility node this one punches above its weight because the question it answers - "is this mask real?" - is the failure mode that silently wastes your time in every mask-heavy pipeline. It's the cheap sentry you put in front of expensive steps.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| threshold | INT | 1270–255 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| percentage | FLOAT | — |
| white_pixels | INT | — |
| total_pixels | INT | — |