Nodes/comfyui_davcha/SoftErosion
ComfyUI Node

SoftErosion

Shrink a mask with a feathered edge, not a hard cut

By dchatel·Created 2 years ago·Updated 13 days ago· 2
SoftErosion
  • mask
  • MASK
size5

An inpainting mask with a hard edge is how you get seams and color mismatches where the regenerated region meets the original. SoftErosion is the fix: it erodes the mask inward by size pixels, but instead of a sharp step it fades the boundary - white to black over those size pixels - so the model blends instead of cutting. If you've ever had a face-swap or inpainting pass leave an obvious boundary, this is the node that makes it disappear.

It's from comfyui_davcha, the "personal QoL and experimental nodes" pack, and it's a proper little utility with a single meaningful knob.

How it works

For each mask in the batch, it runs a distance transform (scipy's distance_transform_edt) - measuring each white pixel's distance to the nearest black pixel - then divides by size and clamps at 1.0. Pixels closer to the edge than size get a fractional value, so the mask shrinks by size pixels and falls off linearly over that same distance. A size of 0 passes the mask through untouched.

Inputs: mask (MASK), size (INT, default 5, min 0). Output: MASK.

The feathering guidance from the inpainting world - 4–12 pixels of blur is typical for blending - maps directly onto this: size 5 is the pack's default and a sane starting point; go lower for fine detail where you don't want the blend bleeding into the subject, higher for soft, wide transitions.

When you'd reach for it

  • Inpainting without a halo - erode the mask a few pixels so the regenerated content doesn't touch (and disturb) the exact edge of the subject.
  • Compositing mattes - soften a harsh cutout before blending onto a new background.
  • De-feathering a bad matte - a mask from a detector often has ragged edges; this regularizes them.

Installing it

# ComfyUI Manager → Install Custom Nodes → search "comfyui_davcha" → Install → Restart
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/dchatel/comfyui_davcha
cd comfyui_davcha
pip install -r requirements.txt

Usual pack catch: nodes.py imports llama_cpp and cv2 at module load while requirements.txt only lists webp and rapidfuzz. If the pack won't load, pip install llama-cpp-python opencv-python and restart.

One thing to keep straight: this erodes and feathers - it makes the masked region smaller and softer. It doesn't dilate or grow a mask, and it can't rescue a mask that's entirely black (that's what SmartMask in the same pack is for). Use it on masks that already represent the right region, and it'll do exactly what the name says.

Categorydavcha

Inputs (2)

NameTypeDefaultDescription
maskMASK
sizeINT5

Outputs (1)

NameTypeDescription
MASKMASK