Mask Enhancer (RMBG) 🎭
Clean up a rough mask with blur, offset, and hole-fill
- mask
- MASK
Every mask you get out of a segmentation model is almost right. There's a jagged edge, a little halo, a hole where the model got confused, a boundary that's a couple pixels too tight. Mask Enhancer is the post-processing pass that fixes those without going back to the model - blur the edge, expand or shrink the boundary, smooth it, fill the holes.
This is one of those nodes you don't know you need until you've spent an afternoon fighting a mask that's 95% there. The RMBG node and BiRefNet give you a solid mask; the last 5% of polish - the part that decides whether your composite looks clean or looks cut-out-with-scissors - lives here.
How it works
It's a stack of classic mask morphology operations, each on its own dial, applied in sequence to whatever mask you feed in. Nothing learned, all deterministic - which is good, because you want this step to be predictable.
The inputs that matter
Everything except the mask is optional, so you only touch what you need:
mask_blur(0–64) - softens the edge. The single most useful one. A rough, aliased mask edge composites badly; a couple points of blur feathers it so the subject sits into the background instead of on top of it.mask_offset(-64 to 64) - grow or shrink the whole mask. Positive expands, negative contracts. Shrink slightly to eat a bright halo fringe around a cutout; expand to make sure you're not clipping the subject's edge.fill_holes(default off) - plugs interior gaps. Turn this on when your model left a hole in the middle of a solid subject (glasses lenses, gaps between limbs the model misread as background).smooth(0–128) - rounds off jagged boundary noise. Different from blur: blur softens opacity at the edge, smooth actually simplifies the mask's shape.sensitivity(0–1, default 1) - adjusts how aggressively the mask is treated overall. Leave at 1 unless you're deliberately tightening.invert_output(default off) - flips the mask, for when you want everything but the masked region.
One output: MASK, cleaned up.
How to install it
- ComfyUI Manager: search
Comfyui-RMBG, install, restart. - Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/1038lab/ComfyUI-RMBG, thenpip install -r requirements.txt, and restart.
No model, pure math - ready immediately.
The trap
Over-processing. It's tempting to crank blur and smooth to hide a bad mask, but past a point you're not enhancing, you're melting - the subject loses its actual shape and the edge goes mushy. If you find yourself pushing these values hard, the real fix is usually upstream: the mask itself is wrong, and no amount of blur saves a mask that missed the hair. Get a better mask from a better model (matting weights for semi-transparent edges, HR weights for big images), then enhance lightly. A small offset to kill a halo plus one or two points of blur handles most real jobs; everything above that is a smell.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | Input mask to be processed. | |
| sensitivityopt | FLOAT | 1.000–1 | Adjust the strength of mask detection (higher values result in more aggressive detection). |
| mask_bluropt | INT | 00–64 | Specify the amount of blur to apply to the mask edges (0 for no blur, higher values for more blur). |
| mask_offsetopt | INT | 0-64–64 | Adjust the mask boundary (positive values expand the mask, negative values shrink it). |
| smoothopt | FLOAT | 0.00–128 | Smooth the mask edges (0 for no smoothing, higher values create smoother edges). |
| fill_holesopt | BOOLEAN | false | Enable to fill holes in the mask. |
| invert_outputopt | BOOLEAN | false | Enable to invert the mask output (useful for certain effects). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |