Nodes/ComfyUI-SBTools/BiRefNet RemoveBG (SBTools)
ComfyUI Node

BiRefNet RemoveBG (SBTools)

The background remover that finally gets hair right — five BiRefNet variants in one node

By Amatsukast·Created 5 months ago·Updated 21 days ago· 2
BiRefNet RemoveBG (SBTools)
  • image
  • background_color
  • IMAGE
  • MASK
  • MASK_IMAGE
modelBiRefNet-HR
mask_blur0
mask_offset0
invert_outputfalse
backgroundAlpha

Removing a background is the operation everyone assumes is solved until they hit flyaway hair, fur, or fabric mesh. That's the case BiRefNet was adopted for, and it's what this node wraps: five BiRefNet model variants behind one interface, with mask refinement built in. It's the flagship of the ComfyUI-SBTools pack, and honestly the reason most people install the pack at all.

If you're newer to the ecosystem, the short version of the BiRefNet story is this: the old default (rembg's u2net) is fast and fine on clean subjects and visibly wrong on hard edges. BiRefNet, a segmentation network that was never built for background removal, became the community default because the difference shows up in a side-by-side rather than in a metric - hair survives. It's MIT-licensed, runs in well under a second at typical resolutions, and ComfyUI even shipped it natively in core in May 2026.

So why use this node instead of the built-in? Two reasons. First, it bundles five variants including BiRefNet_toonout, which extracts outlines instead of a mask - a creative effect core ComfyUI doesn't give you. Second, it's the natural partner to this pack's Alpha to Chroma Key node: cut out, fill, key.

Which model do you actually want?

  • BiRefNet-general - 1024×1024, fast and balanced. The default for most jobs.
  • BiRefNet-HR - 2048×2048, best detail preservation, roughly 4× slower. Reach for it above ~1500px inputs.
  • BiRefNet-portrait - trained on human subjects, better hair and skin separation for people.
  • BiRefNet_dynamic - preserves aspect ratio (256–2304px), so wide and tall images don't get squashed. Use this for non-square inputs.
  • BiRefNet_toonout - line-art / outline extraction instead of a cutout. For stylized effects.

That resolution detail is where most people self-inflict bad results. The square models (general, HR, portrait, toonout) resize your image to a fixed square internally, so feeding a 4K image to the 1024 model downscales it and throws away exactly the edges you were trying to keep.

How it works

Models auto-download on first use to ComfyUI/models/sbtools/BiRefNet/ (from 1038lab/BiRefNet on HuggingFace) and cache afterwards. The node runs the segmentation, then applies your post-processing: mask_blur (0–64) softens edges, mask_offset (−20 to +20) expands or shrinks the boundary, and invert_output swaps foreground/background. The background toggle gives you Alpha (transparent) or Color with a hex background_color.

Outputs are the three you'd expect: IMAGE (cutout, transparent or colored background), MASK (grayscale mask data for wiring into inpaint or detail pipelines), and MASK_IMAGE (an RGB visualization of the mask so you can eyeball it).

Refinement that actually fixes things

Start at mask_blur: 0 and mask_offset: 0. If edges look crunchy, mask_blur: 2–5 smooths them. If the mask cuts too tight (you're losing hair), mask_offset: +2 to +5 pulls it outward. If it's grabbing background, go negative. The blur is applied with a Gaussian and the offset with Max/Min filters, so the results are predictable - no voodoo.

Installing it

Same as every node in the pack - ComfyUI Manager → search "ComfyUI-SBTools" → Install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Amatsukast/ComfyUI-SBTools.git
cd ComfyUI-SBTools
pip install -r requirements.txt

Only huggingface_hub and kornia are required, so no heavy dependency surprises. Restart after install.

Troubleshooting

  • First run hangs / downloads - that's normal, the model is downloading. Watch the console for progress.
  • Wide image looks squashed - you used a square model. Switch to BiRefNet_dynamic.
  • VRAM warnings on HR - BiRefNet-HR wants more memory; general is the budget option and the difference is often small on everyday resolutions.
  • Edges are wrong - almost always a resolution problem (see above) before it's a model problem. Run the same image through general and HR and compare; that's a better use of time than tweaking offsets.

One licensing note: the node code is GPL-3.0 because it's based on ComfyUI-RMBG, but the BiRefNet weights themselves are MIT, so commercial use of the output is fine.

CategorySBTools/Image

Inputs (7)

NameTypeDefaultDescription
imageIMAGEInput image to be processed for background removal.
modelCOMBOBiRefNet-HRSelect the BiRefNet model variant to use.
mask_bluroptINT00–64Specify the amount of blur to apply to the mask edges (0 for no blur, higher values for more blur).
mask_offsetoptINT0-20–20Adjust the mask boundary (positive values expand the mask, negative values shrink it).
invert_outputoptBOOLEANfalseEnable to invert both the image and mask output (useful for certain effects).
backgroundoptCOMBOAlphaChoose background type: Alpha (transparent) or Color (custom background color).
background_coloroptCOLORCODE#222222Choose background color (Alpha = transparent)

Outputs (3)

NameTypeDescription
IMAGEIMAGE
MASKMASK
MASK_IMAGEIMAGE