Nodes/ComfyUI 1hewNodes/Image Mask Blend
ComfyUI Node

Image Mask Blend

Stick a subject on a new background without the gray halo

By 1hew·Created about a year ago·Updated 7 days ago· 33
Image Mask Blend
  • image
  • mask
  • image
  • mask
fill_holetrue
invertfalse
feather0
opacity1.00
expansion0
background_color1.0
background_opacity1.00
output_mask_invertfalse

If you've ever cut a subject out of one image and pasted it somewhere else, you know the drill: the hard edge, the gray fringe, the halo where the mask was a pixel off. Image Mask Blend is the one-node answer to that whole class of problem. It composites an image against a background using a grayscale mask, with the specific controls you actually need - hole filling, edge expand/shrink, feathering, and a background color that can even be sampled from the image itself.

It's the most-searched node in the 1hewNodes pack for good reason. It's a workhorse.

How it works

The math is honest and simple: final = image * mask + background * (1 - mask). The mask decides how much of the subject shows and how much of the background bleeds through. The order of operations matters though, and this node gets it right: it resizes the mask to the image, fills holes, expands or erodes it, applies a Gaussian feather, optionally inverts, scales by opacity, and only then composites. Get a mask from Detect Remove BG or a matting node, feed it in, and you're compositing like a pro without reaching for Photoshop.

The inputs that matter:

  • image - your subject frame.
  • mask - optional. Here's the trap: if you leave it unconnected, the mask is treated as all black, so the whole frame becomes background. Connect it.
  • feather - Gaussian blur radius (0–50) on the mask edge. Start at 2–4 for a soft composite.
  • expansion - dilates (positive) or erodes (negative) the mask in pixels. Fixes the "edge cut too tight" problem.
  • opacity - scales mask strength. 1.0 is a hard composite; 0.8 lets a little background ghost through for a natural blend.
  • background_color - the fun one. It accepts grayscale like 1.0, hex like #f0f0f0, RGB tuples, color names - but also the strategies average (global average color of the image), edge/e (average color of the mask's inner edge), extend/ex (nearest-neighbor extend of edge pixels), and mk/mask (average color inside the mask). edge and extend are the ones that kill the halo: they pull the background color from right next to the subject.
  • background_opacity - mixes the background color with the original image behind the subject, 0–1.

Outputs are image (the composite) and mask (the processed mask, post-feather/post-expansion). That second output is genuinely useful - wire it downstream so every other node uses the same refined selection you just tuned, instead of the raw input mask.

Install

This ships in ComfyUI-1hewNodes. In ComfyUI Manager, search "1hewNodes" and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

Then restart ComfyUI. No model downloads, no heavy dependencies for this node - pure Pillow/NumPy/scipy. One caveat: the pack targets ComfyUI's newer v3 node API, so if the nodes don't show up, update ComfyUI itself first.

Common issues

  • 5 images, 2 masks → 5 outputs, with masks cycled [1,2,1,2,1]. The batch logic broadcasts the smaller side; useful, but know it's happening.
  • Image inputs with alpha - the alpha channel is dropped for compositing (RGB only).
  • Single-letter colors - g maps to lime, not green; invalid color strings silently fall back to white. Typo a hex code and you'll get a white background, not an error.
  • If your background looks "washed out," your background_opacity is below 1.0 - that's the ghost-through effect doing its job.

For the halo problem specifically: crank fill_hole on, dial expansion to 1–2, feather to 2–4, and set background_color to extend. That combo is the one I'd reach for before anything else in this pack.

Category1hewNodes/image/blend

Inputs (10)

NameTypeDefaultDescription
imageIMAGE
fill_holeBOOLEANtrue
invertBOOLEANfalse
featherINT00–50
opacityFLOAT1.000–1
expansionINT0-100–100
background_colorSTRING1.0
background_opacityFLOAT1.000–1
output_mask_invertBOOLEANfalse
maskoptMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK