Nodes/comfyui_imgutils/Mask Edge Operations
ComfyUI Node

Mask Edge Operations

Grow or shrink a mask — and feather it so the edit doesn't scream

By LK-168·Created about a year ago·Updated about a year ago· 1
Mask Edge Operations
  • mask
  • mask
operation
pixels5
feather0
preserve_originalfalse

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 a feather of 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.

Categoryimgutils/mask

Inputs (5)

NameTypeDefaultDescription
maskMASK
operationCOMBO4 options: expand, contract, expand_contract, contract_expand
pixelsINT51–100
featheroptINT00–50Soften edges after operation
preserve_originaloptBOOLEANfalseKeep original mask areas

Outputs (1)

NameTypeDescription
maskMASK