Nodes/lf-nodes/Background Remover
ComfyUI Node

Background Remover

Background removal without leaving your ComfyUI graph

By lucafoscili·Created 2 years ago·Updated 7 days ago· 35
Background Remover
  • image
  • ui_widget
  • image
  • image_list
  • cutout_list
  • mask
  • mask_list
  • stats
transparent_backgroundtrue
background_color#000000
modelu2net

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 (default true) keeps the alpha channel, giving you an actual cutout.
  • Flip it to false and the node fills the background with background_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-use for 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 mask output lets you feather it before it hits your composite.
Category✨ LF Nodes/Filters

Inputs (5)

NameTypeDefaultDescription
imageIMAGEInput image tensor or list of tensors.
transparent_backgroundBOOLEANtrueWhen enabled, keep the background transparent instead of filling it with the chosen color.
background_colorSTRING#000000Hex color used when transparency is disabled (e.g. #FFFFFF).
modelCOMBOu2netrembg ONNX model to use for matting.
ui_widgetoptLF_COMPARE[object Object]

Outputs (6)

NameTypeDescription
imageIMAGEImage tensor with background removed.
image_listIMAGEList of image tensors with background removed.
cutout_listIMAGEList of cutout image tensors.
maskMASKMask tensor used for background removal.
mask_listMASKList of mask tensors used for background removal.
statsJSONJSON object with statistics about the background removal process.