背景移除
Background Removal, No API Key Required
- images
- IMAGE
- MASK
The name is a lie in the best way
BGRemover (shown in ComfyUI as "背景移除") doesn't call some paid background-removal API and it doesn't need a key. It's a thin local wrapper around rembg - the same MIT library that powers half the "free background remover" web apps you've seen - so it runs entirely on your machine. Feed it an image, get back an RGBA image with the background knocked out plus a mask. That's the whole job, and for a solid subject against a contrasting background it's been effectively solved since 2020.
That last sentence sets expectations, so hold onto it. This node's model list is the u2net family: u2net (default), u2netp, u2net_human_seg, u2net_cloth_seg, silueta, and isnet-general-use. These are segmentation models - they label each pixel foreground or background. Fine for products and people, visibly shaky on flyaway hair, fur, veils, or anything genuinely semi-transparent. If your input is hard-edged, this is the fast, free, no-drama answer. If you're fighting hair, the community answer is BiRefNet or InSPyReNet, and this pack doesn't offer those - its dropdown is frozen at the six above.
How it works
The node wraps two rembg calls: new_session(model_name) loads the selected model, then remove() runs it over every image in your batch. Each tensor becomes a PIL image, the background gets cut, and the alpha channel comes back as the MASK output. The IMAGE output keeps that alpha, so it's genuinely transparent RGBA, not a fake-out. On error it quietly returns the original image and an empty black mask instead of crashing - which is worth knowing the first time you see a black MASK and wonder what died.
The inputs you'll actually touch
images- required, an IMAGE. It batches fine, so whole folders go through one run.model_name- the dropdown that matters.u2netpfor speed (slightly less precise),u2net_human_segfor portraits,u2net_cloth_segfor clothing shots. Defaultu2netis the balanced pick.alpha_matting- off by default. Flipping it on runs pymatting to refine edges into fractional alpha, which helps hair and fuzzy edges at a real speed cost. Only turn it on when the plain cutout looks wrong.- The three thresholds (
foreground_threshold240,background_threshold10,erode_size10) are rembg's matting knobs. The defaults are sane. Don't touch them until the matte looks too tight or too loose.
Outputs are IMAGE (RGBA) and MASK (the alpha). One gotcha straight from the README: you can't wire MASK into a PreviewImage node directly. Route it through ComfyUI's built-in MaskToImage first if you want to see it.
Installing it
The easy way is ComfyUI Manager - search "comfyui-bgremover" (or the Chinese display names; the pack is authored in Chinese, so the node titles won't match an English search). Manual install is the usual two steps:
cd ComfyUI/custom_nodes
git clone https://github.com/assemly/comfyui-bgremover.git
cd comfyui-bgremover
pip install -r requirements.txt
Then restart ComfyUI. There's also a python install.py that runs the pip step for you. The heavy dependency is rembg itself, which drags in onnxruntime, pymatting, and pooch. No model weights ship in the repo - rembg downloads them on first use into ~/.u2net (roughly a 175MB file). So the first run of the node can stall while it fetches the weights; a flaky connection or corporate proxy is the classic "it just hangs" cause. Let it finish once and it's cached forever.
Where people get burned
- First-run download. See above. If the first run fails, just re-run - the network is the fragile part, not the node.
- Windows + CUDA. The README's own tip: make sure your CUDA toolkit matches what onnxruntime expects. If CPU inference feels slow on Windows,
pip install onnxruntime-gpuand confirm the runtime picks up your GPU. - It always re-runs. The node marks itself as always-changed, so it re-segments on every queue run with no caching. Usually harmless; a surprise when you're iterating over a big batch.
- Silent fallback. A black MASK next to an unchanged image means the segmentation threw an error, not that the image has no background.
Honest verdict: a capable, zero-config rembg node for the easy 80% of cutouts. For hard edges, keep a BiRefNet or InSPyReNet node in the graph. For everything else - products, portraits on clean backdrops, batch extraction - this is the one that just works.
Inputs (6)
| 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 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |