GetMaskByBiRefNet
Just the mask, no cutout — BiRefNet for inpainting and compositing
- model
- images
- mask
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:
- Your image is resized to the
width×heightpreprocessing resolution. - 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.
- The mask is upscaled back to the original image dimensions (that's what
upscale_methodcontrols on the way in and out). - If
mask_thresholdis above 0, anything below it gets filtered out.
The inputs that matter
- model - a
BIREFNEThandle fromAutoDownloadBiRefNetModelorLoadRembgByBiRefNetModel. - images - your
IMAGEtensor. - 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), ornearest/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_thresholdis 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.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| model | BIREFNET | — | |
| images | IMAGE | — | |
| width | INT | 10240–16384 | The width of the pre-processing image, does not affect the final output image size |
| height | INT | 10240–16384 | The height of the pre-processing image, does not affect the final output image size |
| upscale_method | COMBO | bilinear | Interpolation method for pre-processing image and post-processing mask |
| mask_threshold | FLOAT | 0.0000–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |