Background Remover
Background removal without leaving your ComfyUI graph
- image
- ui_widget
- image
- image_list
- cutout_list
- mask
- mask_list
- stats
Background removal is the most commoditized operation in this whole ecosystem, and this node is the one-click version of it that never leaves your graph. LF_BackgroundRemover wraps rembg - the same matting library that's been doing this job since 2020 - behind a single node. You drop in an image, you get back a cutout, a mask, or a color-filled composite. No separate model-load node, no CLI, no visiting a web service.
That's the pitch, and it's a good one for the common case. If your subject is a solid object on a contrasting background - a product shot, a character render - u2net (the default model) is fast, runs happily on CPU, and has been "good enough" for that job for years. Where people get burned is expecting it to handle the hard cases: flyaway hair, fur, thin structures. u2net's edges are acceptable, not exceptional, and no setting on this node fixes that. For those you'd be reaching for BiRefNet or InSPyReNet in a dedicated node pack anyway.
How it works
The node calls rembg's ONNX inference, which downloads the model file on first use - so the first run on a fresh install sits on a spinner for a while, then everything after is fast. You pick which matting model to use from the model dropdown: the six choices are u2net (default), u2netp (the lightweight one), u2net_human_seg, silueta, isnet-general-use, and isnet-anime. If you're cutting out illustrations, isnet-anime is the one to reach for - the anime variant is visibly better on drawn line art and flat colors.
The two booleans/strings that matter:
transparent_background(defaulttrue) keeps the alpha channel, giving you an actual cutout.- Flip it to
falseand the node fills the background withbackground_color(a hex string like#FFFFFF) instead. Handy when whatever's downstream can't handle RGBA or you want a matte.
Inputs and outputs
Only image is required, plus model which has a sensible default. The outputs are where the node earns its keep: image and image_list are the composited result (as a single tensor and a batch list), cutout_list is just the subject pixels, mask / mask_list give you the alpha as a MASK for feeding an inpainting or compositing step, and stats returns a JSON object with info about the run. The ui_widget input is LF's compare-widget: original vs. cutout, so you can eyeball the mask before it goes anywhere.
Installing it
Part of lf-nodes by lucafoscili, so install the whole pack once:
cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes
then restart ComfyUI. Or just use ComfyUI Manager and search for "LF Nodes". The pack's requirements pull in rembg, opencv-python, and onnxruntime along with the rest of the suite's heavy list, so expect a chunky first install. The rembg model files themselves download on first run of the node.
Troubleshooting
- First run takes forever - that's the ONNX model downloading to your user cache (rembg's
~/.u2net-style folder). It's a one-time thing. - Hair looks like a bad haircut - expected from u2net-class models. Try
isnet-general-usefor slightly better edges, or move to a BiRefNet/InSPyReNet node for anything you care about. - Background shows through on a colored composite - if you're using transparency and compositing later, remember a hard mask can look clean on grey and wrong on a bright background. The
maskoutput lets you feather it before it hits your composite.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image tensor or list of tensors. | |
| transparent_background | BOOLEAN | true | When enabled, keep the background transparent instead of filling it with the chosen color. |
| background_color | STRING | #000000 | Hex color used when transparency is disabled (e.g. #FFFFFF). |
| model | COMBO | u2net | rembg ONNX model to use for matting. |
| ui_widgetopt | LF_COMPARE | [object Object] | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | Image tensor with background removed. |
| image_list | IMAGE | List of image tensors with background removed. |
| cutout_list | IMAGE | List of cutout image tensors. |
| mask | MASK | Mask tensor used for background removal. |
| mask_list | MASK | List of mask tensors used for background removal. |
| stats | JSON | JSON object with statistics about the background removal process. |