Rembg Remove background
Cut the Subject Out — Rembg Remove Background and the Mask You Get For Free
- model
- image
- IMAGE
- MASK
This is the second half of the two-node rembg pair: it takes the session from Load Rembg Model, runs it over your image, and hands you a transparent cutout plus the alpha mask. If you've ever used the rembg CLI or the old A1111 extension, this is that, inside a ComfyUI graph - and honestly, for a solid subject on a plain background, that's all you need. The "solved since 2020" tier of background removal, no fat node pack required.
Just set expectations before you wire it in: rembg's u2net is the fast floor, not the quality ceiling. Great for product shots and batch extractions, mediocre on flyaway hair, glass, veils or anything genuinely semi-transparent - that's BiRefNet or InSPyReNet territory. And one rule from the community that applies here hard: don't background-remove a LoRA training set with this, or your LoRA learns to draw blank backgrounds.
How it works
The node takes your IMAGE tensor, permutes it to channel-first, converts each image in the batch to a PIL image, and calls rembg's remove() with your settings - per image, one at a time. The result is converted back to a ComfyUI tensor, now with four channels: RGB plus alpha. That alpha channel is then split out as a separate MASK output.
The inputs that matter
You must wire in model - the REMBG handle from Load Rembg Model. There's no auto-download and no "just pick u2net" shortcut; if the Load node hasn't run, this node has nothing to work with. Then image, which is your standard IMAGE tensor.
The optional inputs are all forwarded straight to rembg, and all four are things you can usually leave alone:
alpha_matting(off by default) - the one worth knowing. When enabled, rembg runs a proper matting pass instead of a hard segmentation, which is the difference between ragged edges and clean ones on hair. The three threshold ints below it (foreground_threshold240,background_threshold10,erode_size10) are rembg's own defaults and fine as-is. Current rembg bundles thepymattinglibrary it needs; older versions didn't, and would just warn if it was missing.post_process_mask(off by default) - a morphological cleanup on the mask that removes stray specks at the cost of eating a little edge detail. If your cutout has white flecks around the subject, flip this on.
What comes out
IMAGE- the RGBA cutout, transparency baked into the alpha channel. Wire this to Save Image / Preview. Watch out: some downstream nodes silently drop the alpha channel, so if your "transparent" PNG comes back opaque, that's the node after this one, not this one.MASK- the alpha channel as a white-subject-on-black matte. This is the underrated output: feed it into compositing, inpainting, or a mask-edit node without ever touching the RGBA image.
Install and the shared gotchas
Same pack as the Load node - Manager (search "comfyui-rembg") or:
cd ComfyUI/custom_nodes
git clone https://github.com/0x-jerry/comfyui-rembg
Two things to know before you rely on this in a workflow. First, the pack is unmaintained and its only dependency is unpinned rembg, so on a fresh install today the Load node's model-picking step throws a ValueError against modern rembg - and even when it runs, inference is hardcoded to CPU (CPUExecutionProvider), so big images are slow. Second, modern rembg doesn't ship its ONNX runtime by default, so if imports fail with No module named 'onnxruntime', run pip install "rembg[cpu]" (or [gpu]).
If this exact pair is too much fiddling, the maintained alternatives (ComfyUI-RMBG, ComfyUI-Inspyrenet-Rembg, or native BiRefNet in core) do the same job on GPU with better edges. But for a quick product cutout, this two-node setup still gets it done.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| model | REMBG | — | |
| image | IMAGE | — | |
| alpha_mattingopt | BOOLEAN | — | |
| alpha_matting_foreground_thresholdopt | INT | 240 | — |
| alpha_matting_background_thresholdopt | INT | 10 | — |
| alpha_matting_erode_sizeopt | INT | 10 | — |
| post_process_maskopt | BOOLEAN | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |