Mask Edge Operations
Grow or shrink a mask — and feather it so the edit doesn't scream
- mask
- mask
The mask boundary editor
Mask Edge Operations does one thing and does it well: it moves a mask's boundary in or out by a set number of pixels, with a feathering option that makes the result look natural instead of cut with scissors. It sounds trivial until you need it. The classic case: you've got a tight SAM mask of a face, but inpainting inside that exact outline leaves a visible seam at the hairline. Expand the mask by 10 pixels, feather it, and the edit blends. That's this node.
How it works
Four operations, all built on a circular (elliptical) structuring element sized from pixels:
- expand - dilate. Mask grows outward by
pixels. - contract - erode. Mask shrinks by
pixels. - expand_contract - expand then contract. Smooths the boundary while roughly keeping the size; fills inward notches.
- contract_expand - contract then expand. The inverse smoothing; cleans outward spikes.
Two options do the real heavy lifting:
feather(0–50) - Gaussian-softens the edges after the operation. This is the "don't make it look hard-edged" dial, and honestly it's the reason to use this node over plain morphology for most jobs. Zero gives a hard edge; 5–10 gives a soft one.preserve_original- when on, the original mask areas are kept and the operation only adds/subtracts around them. Handy when you want to guarantee the original region is never erased.
Inputs that matter
operation, pixels (default 5, 1–100), and feather. That's the whole toolkit: expand 8, feather 6 is my standing recipe for prepping a face mask for inpainting. Output is a single mask socket, same size as the input.
Install
Part of LK-168/comfyui_imgutils. ComfyUI Manager → search "comfyui_imgutils", or:
cd ComfyUI/custom_nodes
git clone https://github.com/LK-168/comfyui_imgutils
Restart ComfyUI. Pure image math - no models, no downloads.
Common issues
- Contract removed everything. On a thin mask, shrinking by 20 pixels can erase it entirely. Watch the coverage with Mask Info if you're shrinking aggressively.
- Hard edges even with feather on. The feather sigma is
pixels / 3, so afeatherof 1 is nearly invisible. Bump it to 5+ before concluding it's broken. - Compared to Mask Morphology, why both? Morphology does the noise/hole cleanup with arbitrary kernel shapes; this node is purpose-built for boundary nudging plus feathering, which is the operation 90% of detailer workflows actually want. They complement, they don't replace each other.
Short node, real payoff: it's the difference between an inpaint that blends and one you can see from across the room.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| operation | COMBO | 4 options: expand, contract, expand_contract, contract_expand | |
| pixels | INT | 51–100 | — |
| featheropt | INT | 00–50 | Soften edges after operation |
| preserve_originalopt | BOOLEAN | false | Keep original mask areas |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |