ComfyUI Node Runs on cloud

FadeMaskEdges

Stop the Ugly White Halo When You Composite a Cutout

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
FadeMaskEdges
  • binary_image
  • IMAGE
edge_size5
edge_tightness1.10
edge_exponent1.0
smoothing_diameter10
paste_original_blackstrue

FadeMaskEdges takes a hard binary mask and fades its edges from white down to black. That sounds like a minor image-tweak node, but it exists to fix one of the most recognizable artifacts in ComfyUI compositing: the bright fringe that creeps around a cutout's edges when you paste it onto a new background.

Why you'd reach for it

When you cut a subject out of one image and paste it onto another, a mask with razor-sharp edges produces a visible white or colored halo - the "outer pixels creeping in" the author calls it. The fix is to fade the mask edges so the compositing blends instead of slicing. The author's intended recipe: premultiply and alpha-blend a subject's edges to kill the fringe, then apply a slight blur near the edges afterwards. FadeMaskEdges is the premultiply step.

It's a compositing node, so it sits in the same toolbox as the pack's MonoMerge, Color Clip and the GrabCut masks - the manual, art-directed end of the mask spectrum, versus the fully automatic background-removal models (BiRefNet, RMBG, SAM) that dominate most people's first attempts. Those get you 90% of a cutout; this is the cleanup that gets you the last 10%.

How it works

It reads your binary_image, computes the OpenCV L2 distance transform (how far each white pixel is from the nearest black pixel), normalizes by edge_size, then smooths with a bilateral filter so the fade stays local to the boundary instead of getting blobby. From there it darkens white pixels proportionally to their distance from the edge, and - if paste_original_blacks is on (default) - forces the original black pixels to stay pure black.

The inputs that matter

  • edge_size - how wide the fade band is (default 5). Bigger = softer, longer transition.
  • edge_tightness - how quickly the fade falls to black (default 1.1). Higher = snappier edge.
  • edge_exponent - the fade curve shape (default 1 = linear). The author notes that raising it can weaken thin lines, useful for stylized drawings with black outlines.
  • smoothing_diameter - bilateral filter diameter (default 10) that stops the fade from being noisy.
  • paste_original_blacks - keep black pixels truly black instead of letting the fade lift them.

The output is a single IMAGE (the faded mask), which you then use as an alpha/mask input downstream.

Install

It's part of bmad4ever's pack, and this is one of the nodes that needs the requirements:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
pip install -r requirements.txt

then restart ComfyUI. Manager users search "comfyui_bmad_nodes" and it handles opencv-python, scikit-image, simpleeval, and gray2color for you. Without OpenCV installed the CV nodes won't load - if you see a "CV nodes" not-loaded line in the startup log, the requirements are missing.

Common issues

  • "Not loaded" at startup. Missing opencv-python/scikit-image; install the requirements and restart.
  • Fade too aggressive or invisible. edge_size scales the whole band - if the subject has thin features, drop it well below the default 5.
  • Expecting a MASK out. The output is an IMAGE, not a MASK. If a downstream node wants a mask, convert it (or use the mask-compatible path in your graph).

It's the unglamorous finishing node that separates "I cut this out" from "I composited this." Worth learning if you do any manual collage work.

CategoryBmad/CV/Misc

Inputs (6)

NameTypeDefaultDescription
binary_imageIMAGE
edge_sizeFLOAT5
edge_tightnessFLOAT1.101–10
edge_exponentFLOAT1.00.1–10
smoothing_diameterINT102–256
paste_original_blacksBOOLEANtrue

Outputs (1)

NameTypeDescription
IMAGEIMAGE