Background Removal (BiRefNet)
This function block performs high-quality foreground / background segmentation using the BiRefNet model. It produces a binary mask and (optionally) a green overlay visualization of the detected foreground to help you inspect results quickly.
π₯ Inputs (sockets)
Image RGB / BGR image to be segmented.
π€ Outputs (sockets)
Overlay Image with green overlay showing segmented foreground regions.
Mask Binary segmentation mask (0 = background, 255 = foreground).
πΉοΈ Controls
Overlay Toggle to enable or disable the overlay visualization output (shows green overlay over input image).
π¨ Features
High-quality segmentation suitable for objects with complex boundaries and partial transparency.
Produces both a binary mask and a visualization overlay for quick verification.
Automatically handles model loading and device selection (GPU if available).
Designed to work with images of any size (model processing may internally use a fixed-size transform for inference).
Requires additional packages to be available: transformers, torch, torchvision, pillow.
π Usage Instructions
Connect an image source to the
Imageinput (for example:Camera USB,Camera IP (ONVIF),Load Image).Toggle
Overlayif you want a green visual overlay to be produced alongside the binary mask.Inspect the outputs: use
Overlayto preview results visually and useMaskfor downstream processing (measurements, cropping, counting, etc.).Save or log the outputs with
Image WriteorImage Loggerif you need to store results.
π Evaluation
When run, this block returns a binary mask indicating foreground pixels and an optional overlay image where foreground regions are tinted green. Use the mask for further image operations or measurements.
π‘ Tips and Tricks
Preprocess with
Image ResizerorImage Resizeto limit input size if your source images are extremely large. This can reduce memory usage and speed up processing.Denoise or smooth the input using
DenoisingorBlurbefore segmentation to reduce spurious mask artifacts.For stronger contrast between subject and background, try
Auto ContrastorAdjust Colorsprior to feeding the image.To remove small mask holes or speckles, run the
Morphological Transformationsblock on theMaskoutput, then useApply Maskto produce a cleaned cutout.If you want a different segmentation approach for comparison or lower-dependency operation, try
Background Removal (RMBG-1.4)and compare results.Visualize results interactively with
Show Image. To record results automatically, useImage LoggerorImage Write.Use
Image ROI/Image ROI Selectbefore segmentation when you need to segment a specific region only (reduces processing and often improves results).
π οΈ Troubleshooting
If the block reports missing dependencies, install the required packages (transformers, torch, torchvision, pillow) and restart the environment.
If results look noisy or incomplete, try preprocessing with
Image Resizer,Denoising, orAuto Contrast, and postprocess theMaskwithMorphological Transformations.If processing is slow on large images, reduce input size with
Image Resizeror use a smaller source image prior to this block.To inspect intermediate results, connect the
OverlayorMaskoutputs toShow Imageor save them withImage Write.
Last updated
Was this helpful?