Background Removal (RMBG-1.4)
This function block removes background from an input image using a pretrained image-segmentation model. It generates a clean foreground cutout and a binary mask (foreground = 255, background = 0). The model is automatically prepared when you first run the block.
π₯ Inputs
Image A RGB or BGR image to process.
π€ Outputs
Cutout Foreground cutout image (background removed). This can be either RGB on black background or RGBA with alpha depending on the chosen option.
Mask Binary mask image where foreground pixels are 255 and background pixels are 0.
πΉοΈ Controls
Keep RGB on black When unchecked (default) the block returns an RGB cutout on a black background plus the mask. When checked the block returns an RGBA image (alpha channel) plus the mask.
π¨ Features
Generates a binary segmentation mask separating foreground from background.
Option to return RGBA (alpha) or RGB cutout on black background for flexible downstream use.
Model files are automatically fetched the first time the block runs (internet access required).
Works with single images from cameras, files, or streams.
π How it runs
When the block runs it processes the incoming image with the segmentation model to produce a binary mask. The mask is used to create a foreground cutout which is sent together with the mask through the outputs. Model initialization happens automatically (first run may take longer due to model download).
π Usage Recommendations
Feed this block with a clear RGB/BGR image from any image source such as
Load Image,Camera USB,Stream Readeror a saved frame.Use the
Keep RGB on blackoption depending on whether you need an alpha channel or a simple RGB cutout.Combine the outputs with other blocks to refine results or save outputs.
π‘ Tips and Tricks
Improve speed with smaller inputs: use
Image Resizerbefore this block if your input is very large.Crop to the area of interest first using
Image ROIorImage ROI Selectto reduce processing time and improve mask quality.For additional visual checks, send both
CutoutandMaskintoShow Imageor place them side-by-side withCollage Images.Save results automatically with
Image Logger,Image WriteorMulti Image Writewhen you want to archive cutouts and masks.If you need even higher-quality segmentation for difficult boundaries, try the alternative block
Background Removal (BiRefNet)(available in the AI Applications list).Use
Apply Maskif you want to combine the original image and the mask in a custom way (for example to keep some blended background or visualize masked areas).
π οΈ Troubleshooting
If the block reports missing packages, install the required libraries (transformers, pillow) on your system and re-run.
First run may be slower due to automatic model download β subsequent runs will be faster.
If results include stray background fragments, try cropping the image with
Image ROIor increase the input quality (better lighting / contrast).For very noisy images, apply a mild
Bluror a color filtering step (e.g.,HSV Filter) before background removal to improve segmentation stability.
Last updated
Was this helpful?