> For the complete documentation index, see [llms.txt](https://docs.augelab.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.augelab.com/function-blocks/blocks-reference/ai-blocks/background-removal-birefnet.md).

# 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 <a href="#inputs" id="inputs"></a>

`Image` Provide an RGB/BGR image. The block accepts images of any size (larger images may be resized internally for processing).

## 📤 Output sockets <a href="#outputs" id="outputs"></a>

`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 <a href="#controls" id="controls"></a>

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 <a href="#how-it-runs" id="how-it-runs"></a>

* 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 <a href="#features" id="features"></a>

* 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 <a href="#usage" id="usage"></a>

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 <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* 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 <a href="#troubleshooting" id="troubleshooting"></a>

* 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.
