ComfyUI Node

Mask Grow Fast

Mask dilation that doesn't slow to a crawl at high grow values

By zhangp365·Created 2 years ago·Updated 5 months ago· 134
Mask Grow Fast
  • mask
  • MASK
invert_masktrue
grow4
blur4
low_limit0.00
high_limit1.00
enabledtrue

Growing a mask - expanding its white region outward - is one of the most common mask operations there is: feather an inpaint boundary outward a bit so the seam blends, or shrink a segmentation mask inward to avoid picking up edge noise. The problem the author is solving here is specific and real, per their own description: most mask-grow implementations, official or otherwise, get noticeably slower as you push the grow value up - past roughly 20, it starts to drag. This node is built to stay fast regardless of how far you push it.

What it does

  • mask - required, your source mask.
  • grow - an integer from -999 to 999, default 4. Positive expands the mask outward; negative shrinks it inward - the wide negative range is the tell that this node treats "grow" and "shrink" as the same operation in opposite directions, rather than needing a separate shrink node.
  • blur - softens the edge after growing/shrinking, default 4. Set to 0 for a hard edge.
  • invert_mask - defaults to true here, which is worth flagging on its own: a lot of other mask nodes in this pack and elsewhere default this to false, so if you're used to that convention, double-check this one before assuming your mask is behaving normally.
  • low_limit / high_limit (optional, 0–1, default 0 and 1) - clamp the mask's value range after the grow-and-blur pass; at their defaults they don't change anything.
  • enabled (optional, default true) - the same disable-without-rewiring pattern used across this pack's other utility nodes.

Output: a single MASK.

Why speed at high grow values actually matters

A lot of naive dilation implementations work by repeating a small dilation step N times to grow by N pixels - which is exactly why grow values above 20 or so tank performance on the nodes that work that way: you're paying for 20+ sequential passes. Whatever this node is doing internally to stay flat across the -999 to 999 range, the practical upshot is you can push a large grow or shrink value on a big mask without the node becoming the bottleneck in your graph - useful if you're growing masks on video-length batches, where that per-frame cost multiplies fast.

Installing it

ComfyUI Manager: search "ComfyUI-utils-nodes." Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes

Restart ComfyUI. No external dependencies, no models to fetch.

What to watch for

The default invert_mask: true is the one genuine surprise here - if your mask comes out covering the opposite region from what you expected, that's almost certainly it, not a bug in grow. Beyond that, remember grow doubles as shrink: if you're trying to tighten a mask inward and it's expanding instead, you probably want a negative value, not a positive one paired with invert_mask.

Categoryutils/mask

Inputs (7)

NameTypeDefaultDescription
maskMASK
invert_maskBOOLEANtrue
growINT4-999–999
blurINT40–999
low_limitoptFLOAT0.000–1
high_limitoptFLOAT1.000–1
enabledoptBOOLEANtrue

Outputs (1)

NameTypeDescription
MASKMASK