TS Remove Background
BiRefNet background removal with hair you can believe
- image
- background_color
- IMAGE
- MASK
- MASK_IMAGE
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
imageandenable- feed the image; toggleenableoff to pass it through untouched.model- the weight variant. Default HR-matting is right for most people.process_resolution(withuse_custom_resolution) - the working resolution. Drop it if you're OOM.mask_blurandmask_offset- edge softening and boundary expansion/shrink. A couple pixels of blur kills the "sticker" look on hard edges;mask_offsetpositive expands (rescuing wispy edges), negative trims.background/background_color- Alpha (transparent) or a solid color via a COLOR widget.precision-autopicks bf16 on Ampere+ GPUs, fp16 elsewhere, fp32 only for diagnostics. Leave it on auto.temporal_smooth- for video:median3(default) kills single-frame flicker,median5is stronger but lags two frames at clip boundaries,ema_causalis causal with no lag,offfor 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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image to be processed for background removal. | |
| enable | BOOLEAN | true | Enable or disable the background removal process. If disabled, the original image will be passed through. |
| model | COMBO | BiRefNet-HR-matting | Select the BiRefNet model variant to use. |
| use_custom_resolutionopt | BOOLEAN | false | Enable to use a custom resolution specified below. If disabled, the model's default resolution will be used. |
| process_resolutionopt | INT | 1024256–4096 | The resolution for processing the image. It will be adjusted to the nearest multiple of 64. |
| mask_bluropt | INT | 00–64 | Specify the amount of blur to apply to the mask edges (0 for no blur, higher values for more blur). |
| mask_offsetopt | INT | 0-20–20 | Adjust the mask boundary (positive values expand the mask, negative values shrink it). |
| invert_outputopt | BOOLEAN | false | Enable to invert both the image and mask output (useful for certain effects). |
| backgroundopt | COMBO | Alpha | Choose background type: Alpha (transparent) or Color (custom background color). |
| background_coloropt | COLOR | #ffffff | Background color when 'background' is set to 'Color'. COLOR widget supports precise eyedropper picking. |
| precisionopt | COMBO | auto | Inference precision on CUDA. 'auto' picks bf16 on Ampere+ (more numerically robust) and fp16 elsewhere. Force 'fp32' for diagnostics. CPU always runs fp32. |
| temporal_smoothopt | COMBO | median3 | Smooth 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_alphaopt | FLOAT | 0.500–0.99 | Strength 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)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |
| MASK_IMAGE | IMAGE | — |