Modify Mask (Legacy)
Grow, shrink, blur, invert, and batch
- mask
- Mask
- Inverted Mask
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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| expand | INT | 0-16384–16384 | Pixels used to grow each mask; negative values shrink it. |
| incremental_expandrate | FLOAT | 0.000–100 | Additional grow or shrink amount applied after each mask in the batch. |
| tapered_corners | BOOLEAN | true | Uses a cross-shaped kernel for more tapered corners; disabled uses a square kernel. |
| flip_input | BOOLEAN | false | Inverts the input mask before all other processing. |
| blur_radius | FLOAT | 0.000–100 | Gaussian blur radius applied after grow or shrink; zero disables blur. |
| lerp_alpha | FLOAT | 1.000–1 | Blends each batch mask with the previous processed mask; 1 uses only the current mask. |
| decay_factor | FLOAT | 1.000–1 | Adds a decayed previous batch mask before normalization; 1 preserves its full contribution. |
| lower_clamp | FLOAT | 0.00–100 | Minimum output mask value as a percentage. |
| upper_clamp | FLOAT | 100.00–100 | Maximum output mask value as a percentage. |
| fill_holesopt | BOOLEAN | false | Fills enclosed zero-valued holes after grow or shrink. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Mask | MASK | — |
| Inverted Mask | MASK | — |