Background Removal (BiRefNet)
This function block performs high-quality foreground / background segmentation using the BiRefNet model. It creates a clean binary mask for foreground regions and can produce a green overlay visualization on top of the original image for quick inspection.
π₯ Input sockets
Image Provide an RGB/BGR image. The block accepts images of any size (larger images may be resized internally for processing).
π€ Output sockets
Overlay Image visual with segmented foreground shown as a green overlay on the original image.
Mask Binary segmentation mask where foreground pixels are white (255) and background pixels are black (0).
πΉοΈ Controls
This block runs with automatic settings and does not expose manual widgets inside the block. To influence behavior use helper blocks before or after it, for example:
Image Resize β reduce input image size before processing to improve speed and reduce memory use
Image ROI β crop to a region of interest so the model focuses on a smaller area
Apply Mask β combine original image and mask in custom ways after segmentation
Show Image β preview the Overlay or Mask in a larger viewer
Image Logger / Image Write β save masks or overlays for records
βοΈ Running mechanism
The block loads the segmentation model when it is first used. This may download model files and can take time on first run.
If a GPU is available it will be used to accelerate processing; otherwise CPU will be used.
For each input image the block returns a binary mask and a colored overlay (green tint on segmented regions).
Large input images increase processing time and memory usage; resizing the image before feeding it to the block is recommended for faster results.
π― Features
High-quality segmentation that handles complex boundaries and fine details.
Produces both a binary mask suitable for further processing and a visual overlay for quick inspection.
Automatic device selection (GPU if available).
Works with standard image inputs from cameras, files, or previous processing blocks.
π Usage instructions
Provide an image to the
Imageinput socket.Use the returned
Maskfor downstream processing (measurements, ROI operations, compositing).Use the returned
Overlayto preview segmentation quality or present results visually.
Suggested flows:
For faster runs, connect
Image Resizebefore this block.To segment only a part of the scene, use
Image ROIfirst.To save results, connect
Image WriteorImage Loggerto the outputs.To preview results during development, attach
Show Imageto theOverlayorMask.
π‘ Tips and Tricks
If you want a lightweight alternative, try
Background Removal (RMBG-1.4)β it uses a different model and may be faster or produce different cutouts depending on the input.Clean up small mask artifacts using
Morphological TransformationsorImage Thresholdafter getting theMask.If masks look noisy, try running
DenoisingorBlurbefore segmentation to reduce spurious edges.To feed high-resolution images but keep memory manageable, use
Image Resizerto downscale, run segmentation, then useImage ResizeorSuper Resolutionto scale results back if needed.Combine with detection blocks (for example, use results from an object detector to crop the area with
Image ROIand then run this block for per-object background removal).
π οΈ Troubleshooting
Model fails to start or is very slow on first use: the block may be downloading model files and initializing. Wait until the download and initialization complete.
Out of memory errors on GPU: reduce input image size using
Image Resizeor run on CPU by ensuring other GPU workloads are freed.Mask has holes or speckles: apply
Morphological Transformations(fill / open / close) or increase smoothing withBlurbefore segmentation.Foreground missing thin structures: try using the alternative
Background Removal (RMBG-1.4)block to compare results.
Notes:
Required libraries and models are managed outside of the block; installation of the appropriate packages and access to model downloads are necessary for this block to work.
Last updated