Nodes/ComfyUI-UtilsCollection/Modify Mask (Legacy)
ComfyUI Node

Modify Mask (Legacy)

Grow, shrink, blur, invert, and batch

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Modify Mask (Legacy)
  • mask
  • Mask
  • Inverted Mask
expand0
incremental_expandrate0.00
tapered_cornerstrue
flip_inputfalse
blur_radius0.00
lerp_alpha1.00
decay_factor1.00
lower_clamp0.0
upper_clamp100.0
fill_holesfalse

Almost nothing you do with a mask works the first time. The inpainting mask is too tight, the edge is hard and shows a seam, the batch of frame masks drifts between frames. Modify Mask (Legacy) is the cleanup pass: grow or shrink, blur, invert, taper corners, and clamp - with some genuinely useful batch-aware options thrown in.

Mechanically it's OpenCV-style morphology and blending, applied per mask in the batch. expand grows or shrinks the mask by a pixel count; blur_radius softens it with a Gaussian so the composited edge doesn't scream; tapered_corners swaps the dilation kernel between a cross (tapered, softer corners) and a square. flip_input inverts before anything else runs, and the outputs give you both the processed mask and its inverse so you don't need a separate invert node.

The inputs that matter

  • expand - pixels to grow the mask (negative shrinks). The first knob you'll touch. -16384 to +16384, so you can go huge or erase it.
  • blur_radius - Gaussian blur after grow/shrink. Zero disables. This is the fix for hard-edged seams before you composite.
  • tapered_corners - true (default) uses a cross-shaped kernel for softer corners; false gives a square kernel. Matters for clean rectangular crops.
  • flip_input - invert the mask first. Handy when your upstream detector hands you "everything except the subject."
  • fill_holes - optional, fills enclosed zero-valued holes after processing. Use it to close the little specks inside an otherwise-solid mask.

The batch knobs - incremental_expandrate, lerp_alpha, decay_factor, and the clamps - are the unusual part. incremental_expandrate adds a bit more grow/shrink for each mask in the batch, lerp_alpha blends each mask with the previous processed one, and decay_factor adds a decaying previous mask before normalization. If you're processing video frames or animation masks where each frame should ease into the next, these turn a batch of jumpy masks into a smooth one. If that's not what you're doing, leave them at defaults.

The outputs

Mask and Inverted Mask - the processed result and its inverse, both MASK type. The first feeds your inpaint or composite; the inverted one is right there for anything that wants the background instead of the subject.

Installing it

Part of silveroxides/ComfyUI-UtilsCollection. ComfyUI Manager → search ComfyUI-UtilsCollection → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart after. Dependencies are opencv-python and typing-extensions - opencv is where all the morphology lives, and you almost certainly already have it. No models. "(Legacy)" means it's a compat alias for the pack's canonical UC_ModifyMask.

Where people get burned

The clamps are in percentages, and they're easy to misread as 0–1. lower_clamp of 5 means "no value below 5%," not 0.05. And remember the processing order: flip first, then grow/shrink, then blur. If you invert and expect the blur to hit the new boundary, it does - but a flip_input plus a big expand can gobble a mask you thought was safe, because the expansion now applies to the inverted side. When frames look like they're crawling, check incremental_expandrate isn't nonzero - it's the one input that quietly changes each mask in the batch.

Categoryutils/mask

Inputs (11)

NameTypeDefaultDescription
maskMASK
expandINT0-16384–16384Pixels used to grow each mask; negative values shrink it.
incremental_expandrateFLOAT0.000–100Additional grow or shrink amount applied after each mask in the batch.
tapered_cornersBOOLEANtrueUses a cross-shaped kernel for more tapered corners; disabled uses a square kernel.
flip_inputBOOLEANfalseInverts the input mask before all other processing.
blur_radiusFLOAT0.000–100Gaussian blur radius applied after grow or shrink; zero disables blur.
lerp_alphaFLOAT1.000–1Blends each batch mask with the previous processed mask; 1 uses only the current mask.
decay_factorFLOAT1.000–1Adds a decayed previous batch mask before normalization; 1 preserves its full contribution.
lower_clampFLOAT0.00–100Minimum output mask value as a percentage.
upper_clampFLOAT100.00–100Maximum output mask value as a percentage.
fill_holesoptBOOLEANfalseFills enclosed zero-valued holes after grow or shrink.

Outputs (2)

NameTypeDescription
MaskMASK
Inverted MaskMASK