Nodes/ComfyUI Timesaver Nodes/TS Remove Background
ComfyUI Node

TS Remove Background

BiRefNet background removal with hair you can believe

By AlexYez·Created 2 years ago·Updated a day ago· 12
TS Remove Background
  • image
  • background_color
  • IMAGE
  • MASK
  • MASK_IMAGE
enabletrue
modelBiRefNet-HR-matting
use_custom_resolutionfalse
process_resolution1024
mask_blur0
mask_offset0
invert_outputfalse
backgroundAlpha
precisionauto
temporal_smoothmedian3
ema_alpha0.50

If you've cut out a subject and lost the flyaway hair, you've met the difference between u2net-era background removal and BiRefNet. TS Remove Background wraps BiRefNet - the model the background-removal doc calls the default recommendation as of mid-2026 - and adds the practical conveniences: a model picker, resolution control, mask blur/offset, temporal smoothing for video, and three outputs (the cutout, the mask, and a mask preview image).

This is the "isolate the subject" node for product shots, compositing, feeding clean alphas into other tools, or just killing a busy background before an img2img pass. It's a download-on-first-use model node, so unlike the pack's pure-math nodes it needs a moment to fetch weights - but it's a one-time cost.

How it works

BiRefNet (Bilateral Reference Network) was actually built for dichotomous image segmentation, not background removal - it just happens to be exceptional at it. The architecture's trick is its two-module design: a localization module that places the object from global semantics, and a reconstruction module that rebuilds the mask against two references at once - hierarchical image patches and gradient maps. That gradient supervision is why hair and fine edges survive; it pushes attention onto fine detail.

The node fetches weights from the ZhengPeng7 HuggingFace repos on first use, into models/BiRefNet/<variant>/. The model dropdown matters more than most: HR-matting is the default and the one to keep for high-res input; general is the classic BiRefNet; portrait is tuned for people; DIS is the dichotomous-image-segmentation weight. process_resolution (default 1024, snapped to multiples of 64) sets the working resolution - this is the VRAM dial.

The inputs that matter

  • image and enable - feed the image; toggle enable off to pass it through untouched.
  • model - the weight variant. Default HR-matting is right for most people.
  • process_resolution (with use_custom_resolution) - the working resolution. Drop it if you're OOM.
  • mask_blur and mask_offset - edge softening and boundary expansion/shrink. A couple pixels of blur kills the "sticker" look on hard edges; mask_offset positive expands (rescuing wispy edges), negative trims.
  • background / background_color - Alpha (transparent) or a solid color via a COLOR widget.
  • precision - auto picks bf16 on Ampere+ GPUs, fp16 elsewhere, fp32 only for diagnostics. Leave it on auto.
  • temporal_smooth - for video: median3 (default) kills single-frame flicker, median5 is stronger but lags two frames at clip boundaries, ema_causal is causal with no lag, off for stills. This is what stops a video cutout from "boiling."

Outputs: IMAGE (the cutout - transparent or on the chosen background), MASK (the alpha), and MASK_IMAGE (the mask as a viewable image). Wire IMAGE to a saver/compositor and MASK into anything that needs alpha.

Installing it

comfyui-timesaver via ComfyUI Manager ("Timesaver") or:

cd ComfyUI/custom_nodes
git clone https://github.com/AlexYez/comfyui-timesaver
cd comfyui-timesaver
python -m pip install -r requirements.txt

Restart ComfyUI; weights download on first run.

Gotchas

The classic failure is an out-of-memory at high process_resolution - the troubleshooting section of the README points straight at this node's resolution control. Drop it to 768 or 512 and rerun. Second: if a model variant fails to download, the pack falls back through mirror sources (the ZhengPeng7 repos have occasionally gone gated or archived), so a transient failure usually resolves itself on retry. And the honest caveat from the background-removal doc: no model wins everything. BiRefNet is the quality default for hair and semi-transparency, but for anime or line art you may find other weights better - the model dropdown exists precisely so you can A/B without leaving the graph.

CategoryTS/Image/Cutout

Inputs (13)

NameTypeDefaultDescription
imageIMAGEInput image to be processed for background removal.
enableBOOLEANtrueEnable or disable the background removal process. If disabled, the original image will be passed through.
modelCOMBOBiRefNet-HR-mattingSelect the BiRefNet model variant to use.
use_custom_resolutionoptBOOLEANfalseEnable to use a custom resolution specified below. If disabled, the model's default resolution will be used.
process_resolutionoptINT1024256–4096The resolution for processing the image. It will be adjusted to the nearest multiple of 64.
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_coloroptCOLOR#ffffffBackground color when 'background' is set to 'Color'. COLOR widget supports precise eyedropper picking.
precisionoptCOMBOautoInference precision on CUDA. 'auto' picks bf16 on Ampere+ (more numerically robust) and fp16 elsewhere. Force 'fp32' for diagnostics. CPU always runs fp32.
temporal_smoothoptCOMBOmedian3Smooth alpha across frames to reduce 'boiling' edges in video. 'median3' (default) kills random 1-frame flicker; 'median5' is stronger (2-frame lag at clip boundaries); 'ema_causal' is causal averaging (no lag, can blur fast motion); 'off' disables. No-op for single images. Adds ~N*H*W*4 bytes RAM during the pass.
ema_alphaoptFLOAT0.500–0.99Strength of the causal EMA when temporal_smooth = 'ema_causal'. Higher = more smoothing (more lag for moving objects); lower = closer to the raw per-frame alpha.

Outputs (3)

NameTypeDescription
IMAGEIMAGE
MASKMASK
MASK_IMAGEIMAGE