ComfyUI Node

GrowMask Ultra-Fast

Grow or shrink any mask, video batch included

By lihaoyun6·Created 11 months ago·Updated 11 months ago· 39
GrowMask Ultra-Fast
  • mask
  • mask
expand_by0
tapered_cornerstrue
batch_size5
devicecpu

Every segmentation workflow ends with the same two complaints: the mask is too tight (hard seams when you inpaint) or too loose (it bleeds into the background). GrowMask Ultra-Fast is the fix for both - it inflates or shrinks any mask by a set number of pixels, and unlike the stock ComfyUI GrowMask node it's batch-aware, so it handles video frame stacks without you looping over them. It's the unglamorous cleanup node that turns a technically-correct mask into one you'd actually sample with.

How it works

No neural network here - this is plain morphological image processing. The mask runs through kornia's dilation (to grow) or erosion (to shrink), applied one pixel at a time in a loop, so expand_by literally means "this many pixels of growth." Two details keep it from being a dumb square-kernel expand: the tapered_corners toggle switches between a diamond-weighted kernel (rounded, organic edges - the default, and almost always what you want) and a full square kernel (hard corners), and the whole operation processes the batch in chunks of batch_size with a progress bar, which is the "ultra fast" bit - it's built for feeding dozens of video frames at once. If expand_by is zero it short-circuits and returns your mask untouched.

The inputs that matter

  • mask - the MASK you want to adjust. Wire in the output of Segformer B2 Clothes Ultra-Fast (or anything else).
  • expand_by - the whole show. Positive grows, negative shrinks, range −255 to 255. For inpainting seams, 4–12 pixels of growth is the classic range; shrink for matting-style tightness.
  • tapered_corners - default on. Leave it on unless you specifically need square edges.

The other two inputs are plumbing: batch_size (default 5, up to 50) chunks the work, and device picks where the morphology runs - CPU is fine here since these ops are cheap, but for big video batches your GPU will chew through them faster.

Outputs

A single mask output, same shape as the input - just grown or shrunk. That's it. Wire it into your inpainting set, a Mask To Bbox (SAM2) node, or a compositing pass.

Installing it

It's part of ComfyUI-Segformer_Ultra_Fast, so the usual drill. ComfyUI Manager → search "Segformer Ultra Fast" → Install → restart, or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/lihaoyun6/ComfyUI-Segformer_Ultra_Fast

Unlike the segmentation nodes in this pack, this one downloads no models and needs nothing beyond what the pack already installs - kornia is the real dependency (it does the dilation/erosion), along with transformers, numpy, pillow and huggingface_hub. You can use it the moment ComfyUI restarts, with zero first-run downloads.

Common issues

  • Mask unchanged - expand_by is 0, which short-circuits by design.
  • Ugly square edges - tapered_corners got switched off; turn it back on.
  • Slow on huge images - the loop runs one pixel of growth per iteration, so expanding by 50 pixels on a 4K mask is 50 morphology passes. It still beats doing it per-frame manually; just don't crank expand_by past what the task needs.

The honest framing: this isn't an exciting node, and "Ultra-Fast" in its name oversells a handful of kornia passes. But it's the one you'll reach for every time a segformer mask comes out a hair too tight for a clean inpaint - and it's the reason the pack's main node can stay honest at the edges while you handle the final pixel math here.

CategorySegformer Ultra-Fast/Mask

Inputs (5)

NameTypeDefaultDescription
maskMASK
expand_byINT0-255–255
tapered_cornersBOOLEANtrue
batch_sizeINT51–50
deviceCOMBOcpu1 options: cpu

Outputs (1)

NameTypeDescription
maskMASK