For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

  1. Provide an image to the Image input socket.

  2. Use the returned Mask for downstream processing (measurements, ROI operations, compositing).

  3. Use the returned Overlay to preview segmentation quality or present results visually.

Suggested flows:

  • For faster runs, connect Image Resize before this block.

  • To segment only a part of the scene, use Image ROI first.

  • To save results, connect Image Write or Image Logger to the outputs.

  • To preview results during development, attach Show Image to the Overlay or Mask.

πŸ’‘ 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 Transformations or Image Threshold after getting the Mask.

  • If masks look noisy, try running Denoising or Blur before segmentation to reduce spurious edges.

  • To feed high-resolution images but keep memory manageable, use Image Resizer to downscale, run segmentation, then use Image Resize or Super Resolution to scale results back if needed.

  • Combine with detection blocks (for example, use results from an object detector to crop the area with Image ROI and 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 Resize or run on CPU by ensuring other GPU workloads are freed.

  • Mask has holes or speckles: apply Morphological Transformations (fill / open / close) or increase smoothing with Blur before 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