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

  1. Connect an image source to the Image input (for example: Camera USB, Camera IP (ONVIF), Load Image).

  2. Toggle Overlay if you want a green visual overlay to be produced alongside the binary mask.

  3. Inspect the outputs: use Overlay to preview results visually and use Mask for downstream processing (measurements, cropping, counting, etc.).

  4. Save or log the outputs with Image Write or Image Logger if 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 Resizer or Image Resize to 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 Denoising or Blur before segmentation to reduce spurious mask artifacts.

  • For stronger contrast between subject and background, try Auto Contrast or Adjust Colors prior to feeding the image.

  • To remove small mask holes or speckles, run the Morphological Transformations block on the Mask output, then use Apply Mask to 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, use Image Logger or Image Write.

  • Use Image ROI / Image ROI Select before 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, or Auto Contrast, and postprocess the Mask with Morphological Transformations.

  • If processing is slow on large images, reduce input size with Image Resizer or use a smaller source image prior to this block.

  • To inspect intermediate results, connect the Overlay or Mask outputs to Show Image or save them with Image Write.

Last updated

Was this helpful?