高级背景移除
The Same rembg Cutout, Plus a One-Knob Background Color
- images
- IMAGE
- MASK
Same engine, two extra knobs
BGRemoverAdvancedMask ("高级背景移除" in ComfyUI) is the same rembg wrapper as its sibling BGRemover, with exactly two things added: a post-processing toggle and a background color input. Same model dropdown, same alpha matting controls, same IMAGE + MASK outputs, same install. Everything in the BGRemover article - the u2net-family model list, the first-run model download, the Windows CUDA note - applies here verbatim.
So why does this node exist? Because "remove the background" is rarely the whole task. Half the time you want the cutout sitting on a clean white swatch for a product listing, or on black to check your matte, or on a specific brand color. This node folds that step in so you don't need a separate compositing node sitting downstream.
The two inputs that make it "advanced"
-
post_process- off by default. When on, it runs a gentle Gaussian blur (radius 0.5) over the alpha channel to feather the edge, and writes that smoothed alpha back into both the IMAGE and the MASK. It's a light cosmetic touch, not a miracle worker: it softens a hard segmentation edge by half a pixel, at a small speed cost. I'd leave it off until you look at a cutout and think "that edge is just a touch harsh." -
background_color- the star here. Default istransparent, so out of the box it behaves exactly like BGRemover. Set it towhite,black,red,green,blue, or any hex code like#FF5733, and the node composites the cutout over that color using PIL's alpha compositing. The MASK output stays untouched, so you can still grab the clean cutout mask even after the IMAGE is flattened onto a background.
One trap, and it's in the code rather than the docs: the color string is matched against a fixed list. transparent, white, black, red, green, blue, or a #-prefixed hex - anything else silently falls back to white. Misspell "transparent" and you'll get a white background and no idea why. Worth remembering.
Wiring it
Same as the basic node. IMAGE out is RGBA; MASK is the alpha channel. The README's note still applies: MASK won't go straight into a PreviewImage - route it through MaskToImage first. And since it's the same rembg wrapper, the shared gotchas hold: the first run downloads the model into ~/.u2net, the node always re-executes (no caching), and a failed image returns the original plus an empty black mask instead of erroring.
Install is identical - ComfyUI Manager searching "comfyui-bgremover", or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/assemly/comfyui-bgremover.git
cd comfyui-bgremover
pip install -r requirements.txt
then restart. rembg pulls in onnxruntime, pymatting, and pooch; the weights download on first run, not at install time.
Which one should you use?
Honest answer: if you're installing the pack at all, just use this one. It's strictly BGRemover plus two optional extras that default to doing nothing, so there's no downside. The only argument for the plain node is a marginally smaller surface area, and that's cosmetic. For a solid subject on a contrasting background - the u2net family's home turf - either node is the fast, local, no-API answer. For hair and fine edges, keep a BiRefNet or InSPyReNet node in the graph; this pack stops at u2net, and no amount of background color is going to fix a bad matte.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| model_nameopt | COMBO | u2net | 6 options: u2net, u2netp, u2net_human_seg, u2net_cloth_seg, silueta, isnet-general-use |
| alpha_mattingopt | BOOLEAN | false | — |
| alpha_matting_foreground_thresholdopt | INT | 2400–255 | — |
| alpha_matting_background_thresholdopt | INT | 100–255 | — |
| alpha_matting_erode_sizeopt | INT | 100–1000 | — |
| post_processopt | BOOLEAN | false | — |
| background_coloropt | STRING | transparent | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |