Nodes/Link Comfy Nodes/Average Mask Region Size
ComfyUI Node

Average Mask Region Size

Measure how big your tracked mask actually is

By Mister-Link·Created 9 months ago·Updated 24 days ago· 0
Average Mask Region Size
  • masks
  • avg_width
  • avg_height
  • frames_used
threshold0.50
ignore_empty_framestrue

This isn't a processing node - it's a diagnostic one, and it's genuinely useful for exactly that reason. If you're running a masked video pipeline (a tracked face, a SAM-segmented subject, anything feeding a VACE-style masked repair or inpaint), you often need to know how big that mask region actually is, on average, across the whole batch - to size a downstream crop, sanity-check that tracking didn't drift, or catch frames where the mask silently vanished. Average Mask Region Size does exactly that measurement and nothing else.

Per the pack's own description: it "calculates the average width and height of the white/non-zero mask region across a batch of mask frames."

How it works

It scans every mask frame in your batch, finds the bounding box of the active (white/non-zero) region in each, and averages the width and height across the batch - with an option to exclude frames where the mask is effectively empty, so a handful of blank tracking failures don't drag your average toward zero and hide the real number.

The inputs and outputs that matter

  • masks (MASK, required) - the mask batch to measure.
  • threshold (FLOAT, default 0.5, 0–1) - the cutoff for counting a mask pixel as "active." Soft-edged masks (from a blurred SAM output, say) may need this tuned up or down depending on how conservative you want the region estimate to be.
  • ignore_empty_frames (BOOLEAN, default true) - excludes frames with no active mask region from the average. Leave it on for a realistic number; turning it off will pull your average down if any frames genuinely have an empty mask.

Three outputs: avg_width (INT), avg_height (INT), and frames_used (INT) - that last one tells you how many frames actually contributed to the average, which is itself a useful check. If frames_used comes back much lower than your total batch size, that's a sign your masking step is failing on more frames than you think.

How to install it

Via ComfyUI Manager: search "Link Comfy Nodes," install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Mister-Link/link-comfy-nodes
pip install -r link-comfy-nodes/requirements.txt

Restart ComfyUI.

Common issues & troubleshooting

Not sure this node is for you. If you're not running a mask-heavy video pipeline, you probably don't need this one - it's a niche measurement tool, not a general utility. It earns its place specifically in workflows where you're tracking or segmenting a region across frames and need to make a sizing decision (crop dimensions, a downstream latent target) based on real data instead of a guess.

frames_used much lower than expected. That's your actual signal to go investigate the masking step upstream, not this node - it means a real chunk of your batch is producing empty masks. Check whichever detector or tracker feeds this node before assuming the average itself is wrong.

Result skewed smaller or larger than it looks visually. Double-check threshold - a low threshold counts faint mask edges as active and inflates the region; a high threshold ignores soft edges and can undercount it. If the numbers don't match what you see when eyeballing the mask, that's usually the first thing to adjust.

Categorylink/video

Inputs (3)

NameTypeDefaultDescription
masksMASK
thresholdFLOAT0.500–1
ignore_empty_framesBOOLEANtrue

Outputs (3)

NameTypeDescription
avg_widthINT
avg_heightINT
frames_usedINT