Detect Remove BG Refine
Fix the fuzzy edges your background-removal mask left behind
- image
- mask
- image
- mask
The dirty secret of background removal is that the mask is usually the weak link. RMBG and friends give you a subject that's broadly right but with haloed, fuzzy, color-fringed edges - fine for a preview, terrible for a final composite. Detect Remove BG Refine (1hew_DetectRemoveBGRefine) is the cleanup pass: it takes your original image plus the rough mask and turns them into a clean RGBA cutout with the edge gunk removed.
It's designed to sit directly after the pack's Detect Remove BG: cutout out of that node, then this one polishes it. You could also feed it any mask you have lying around - the inputs are just image and mask.
How it works
The pipeline is a proper matting-cleanup chain, and the input order matters: image must be the original photo, not the already-composited cutout, because the node needs the true background pixels to remove the color bleed. It then:
- Refines the alpha - bilateral + gaussian filtering to smooth the mask while preserving edge structure, then pushes the confident core toward fully opaque so you don't get a translucent subject.
feathersoftens the edge transition (0–64, default 1). Higher = softer, dreamier edge.subject_protect(default 0.85) controls how aggressively the core stays solid - lower it and more of the subject's edge becomes semi-transparent.decolor_edgeis the star: it estimates the background color and removes it from the edges, killing the white/black halo and color fringing that make cutouts look pasted-on.typechooses the edge character -bitmapkeeps a soft organic edge,vectorruns contour detection with Chaikin smoothing for harder, cleaner shapes.
Inputs and outputs
- image - the original (pre-removal) image. Non-negotiable.
- mask - the rough alpha from your removal node.
- type -
bitmap(default) orvector. - subject_protect - core opacity protection, 0–1.
- feather - edge softness, 0–64.
- decolor_edge - halo/fringe removal strength, 0–1.
- image - the refined RGBA cutout.
- mask - the refined alpha.
Installing it
It's part of the 1hewNodes pack:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
or via ComfyUI Manager ("1hewNodes"), then restart. No extra model downloads - it's pure OpenCV/Numpy image processing.
The honest take
This node fixes the exact failure the background-removal KB calls out: a cutout that "looks clean against a grey preview and falls apart against a coloured background." The decolor_edge control is the reason to use it - crank it to 1.0 and hair edges lose their white fringe noticeably. Two caveats. First, it can't conjure detail the mask never had; if your RMBG mask chopped off hair strands entirely, refining won't bring them back (that's what a matting-weight model is for). Second, type: vector is situational - it's great for product shots and clean silhouettes, wrong for hair. Start with bitmap and feather 1–2, then tune. For the price of two nodes in your graph, you get cutouts that survive being composited onto a colored background - which is the difference between "removed" and "actually usable."
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| type | COMBO | bitmap | 2 options: bitmap, vector |
| subject_protect | FLOAT | 0.850–1 | — |
| feather | FLOAT | 1.00–64 | — |
| decolor_edge | FLOAT | 1.000–1 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |