Nodes/ComfyUI_BiRefNet_ll/GetMaskByBiRefNet
ComfyUI Node Runs on cloud

GetMaskByBiRefNet

Just the mask, no cutout — BiRefNet for inpainting and compositing

By lldacing·Created 2 years ago·Updated about a year ago· 289
GetMaskByBiRefNet
  • model
  • images
  • mask
width1024
height1024
upscale_methodbilinear
mask_threshold0.000

Sometimes you don't want a transparent cutout at all - you want the mask. You're about to inpaint the background away, feed a ControlNet, or composite the subject onto a new scene, and what you need from BiRefNet is the shape, not the pixels. GetMaskByBiRefNet is the node that stops at the mask and hands it straight to you.

It's the first stage of RembgByBiRefNetAdvanced pulled out on its own. Where the Advanced node goes on to estimate clean foreground colours, this one runs the segmentation and returns only the soft alpha - cheaper, faster, and you don't pay for a colour-decontamination pass you're not going to use.

How it works

Exactly the same inference as the Advanced node's first stage:

  1. Your image is resized to the width × height preprocessing resolution.
  2. BiRefNet runs, and the network's logits are passed through a sigmoid to become a soft mask - values between 0 and 1, not a hard cut.
  3. The mask is upscaled back to the original image dimensions (that's what upscale_method controls on the way in and out).
  4. If mask_threshold is above 0, anything below it gets filtered out.

The inputs that matter

  • model - a BIREFNET handle from AutoDownloadBiRefNetModel or LoadRembgByBiRefNetModel.
  • images - your IMAGE tensor.
  • width / height - preprocessing resolution only. The tooltip says it plainly: "does not affect the final output image size." Default 1024, which matches the standard weights' training resolution. Feed a huge image to the 1024 model and it downsizes internally, so for big inputs pair this node with the General-HR or General-dynamic weights.
  • mask_threshold - default 0 (off). Raised slightly (try 0.05–0.1), it zeros out low-confidence mask pixels, which is the classic fix for the speckle BiRefNet sometimes leaves floating outside the subject on busy backgrounds. Too high and you start eating the soft hair edges, so start small.
  • upscale_method - interpolation used when resizing to the pre-processing resolution and back: bilinear (default, good all-round), bicubic (slightly sharper), or nearest / nearest-exact (crisp but can stair-step).

Output is a single mask (MASK). It's the same type every ComfyUI inpainting, masking, and compositing node expects, so wire it into whatever consumes a mask - an inpaint workflow, MaskToImage for a visual check, or a ControlNet that wants a matte.

Install

Standard pack install - ComfyUI Manager (search ComfyUI_BiRefNet_ll) or:

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

Deps are light (numpy, opencv-python, timm), and the BiRefNet code is bundled with the pack. You still need a model - AutoDownloadBiRefNetModel fetches it into models/BiRefNet on first run.

Where people get tripped up

  • Mask looks grey, not black-and-white - that's expected. It's a soft alpha, and the grey is genuinely useful for compositing and feathering. If you want a hard binary, that's what mask_threshold is for.
  • Great mask at small size, garbage at 4K - the resolution-matching rule again. The model is only as good as what its training resolution allows; use HR or dynamic weights for large inputs.
  • Mask is great, but the cutout still has fringed edges - then you're at the wrong node for the remaining problem. The mask says where the subject is; the colour under it is a separate issue, and that's BlurFusionForegroundEstimation's job.

If all you ever wanted was the cutout and its matte in one step, RembgByBiRefNetAdvanced returns both - this node is for when the mask is the product.

Categoryrembg/BiRefNet

Inputs (6)

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
mask_thresholdFLOAT0.0000–1

Outputs (1)

NameTypeDescription
maskMASK