Nodes/ComfyUI_BiRefNet_ll/RembgByBiRefNetAdvanced
ComfyUI Node Runs on cloud

RembgByBiRefNetAdvanced

The BiRefNet cutout node with the color-bleed fix built in

By lldacing·Created 2 years ago·Updated about a year ago· 289
RembgByBiRefNetAdvanced
  • model
  • images
  • image
  • mask
width1024
height1024
upscale_methodbilinear
blur_size90
blur_size_two6
fill_colorfalse
color0
mask_threshold0.000

If you've cut out hair or fur with a plain rembg node and wondered why the edges come out with a grey or green halo, this is the node you were missing. RembgByBiRefNetAdvanced is the flagship of the ComfyUI_BiRefNet_ll pack: it runs BiRefNet to find the subject, then runs Photoroom's fast-foreground-estimation on top so the background colour doesn't bleed into semi-transparent edges. That second step is what separates a cutout that looks pasted-on from one that survives being dropped onto a new background.

BiRefNet is the model that quietly replaced rembg's u2net as this ecosystem's default background remover - its bilateral-reference architecture is why flyaway hair survives at all. This pack just wraps it with more knobs than the bare node.

How it works

Two stages, and the node name tells you exactly what "Advanced" means:

  1. Mask inference (shared with GetMaskByBiRefNet). Your image is resized to the width × height you set, pushed through BiRefNet, and the output mask is upscaled back to the original size. The model's answer is a soft alpha, not a hard cut.
  2. Foreground estimation (shared with BlurFusionForegroundEstimation). A blur-fusion pass estimates the clean foreground colour behind the mask, using the alpha map to separate what belongs to the subject from what's actually background glowing through. It runs a coarse blur then a fine one - that's blur_size and blur_size_two.

The takeaway: the mask tells you where the subject is, and the second stage fixes what colour it should be.

The inputs that matter

  • model - a BIREFNET handle from AutoDownloadBiRefNetModel or LoadRembgByBiRefNetModel.
  • width / height - pre-processing resolution only. The tooltip is blunt about it: "does not affect the final output image size." Leave them at 1024 unless you know why you're changing them. This is where people get burned: BiRefNet's standard weights were trained at 1024, so if your source is 4K, the model internally downsizes and the hair detail you wanted is gone before inference starts. Switch to the General-HR or General-dynamic weights for big inputs instead of cranking these numbers.
  • blur_size / blur_size_two - how wide the colour-decontamination blur runs (defaults 90 and 6). If edges still show a coloured fringe, nudge blur_size up; if the subject's own edges are getting smeared, back it off.
  • mask_threshold - default 0 means off. Raise it slightly (try 0.05) to hard-filter the soft, low-confidence speckle the model sometimes leaves outside the subject.
  • fill_color / color - when fill_color is on, the background becomes a solid RGB colour instead of transparency. Handy for previews or when you're compositing onto a flat backdrop.

Outputs are image (RGBA with real transparency when fill_color is off) and mask (a MASK you can wire into inpainting, ControlNet, or an alpha-composite node).

Install

Via ComfyUI Manager, search ComfyUI_BiRefNet_ll and hit install. Or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/ComfyUI_BiRefNet_ll.git
cd ComfyUI_BiRefNet_ll
pip install -r requirements.txt   # numpy, opencv-python, timm
# restart ComfyUI

The pack bundles the BiRefNet code itself, so the only real Python deps are numpy, opencv-python and timm - nothing exotic. You still need a model: AutoDownloadBiRefNetModel fetches it into models/BiRefNet on first run, or you drop the .safetensors files there yourself.

Troubleshooting

  • Halo on hair edges → raise blur_size, or use the Matting weights for genuinely semi-transparent material (veils, glass) - a segmentation mask can't represent a half-transparent pixel.
  • Huge inputs, mediocre mask → you're feeding a 1024-trained model a 4K image. Use General-HR or General-dynamic.
  • VRAM tight → load the model with dtype: float16. BiRefNet's author measured roughly 3.5GB at FP16 against 4.8GB at FP32, with no meaningful accuracy loss.

One honest caveat: BiRefNet vs InSPyReNet is a live argument with no settled winner - run both on your own three hardest images before standardising. And if you're cutting out a solid object on a contrasting background, rembg's u2net is still faster and good enough. This node earns its VRAM on hair, fur, and fabric mesh.

Categoryrembg/BiRefNet

Inputs (10)

NameTypeDefaultDescription
modelBIREFNET
imagesIMAGE
widthINT10240–16384The width of the pre-processing image, does not affect the final output image size
heightINT10240–16384The height of the pre-processing image, does not affect the final output image size
upscale_methodCOMBObilinearInterpolation method for pre-processing image and post-processing mask
blur_sizeINT901–255
blur_size_twoINT61–255
fill_colorBOOLEANfalse
colorINT00–16777215
mask_thresholdFLOAT0.0000–1

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK