Remove Background
Changed onTry out this capability in Bria's sandbox
Description
The Remove BG Route can be used to remove the background of an image. This route leverages Bria's newest model, RMBG 2.0. For more details and to explore the model, check out the Hugging Face demo.
Guided Cutout
Add an optional prompt to change what the cutout keeps, for example "the person with the mat and the plant" or "only the chair". The endpoint starts from the same cut and adds, drops or narrows only what the prompt names. It returns the same cutout as Guided Remove Background.
Content Moderation
This endpoint includes granular content moderation controls to ensure safe usage across all stages of processing:
- Input Image Moderation – Scans the uploaded image and stops processing if inappropriate or restricted content is detected.
- Output Image Moderation – Evaluates the generated image and blocks the response if it violates safety guidelines.
Constraints
The Bria API supports JPEG, PNG and WEBP files in RGB, RGBA, or CMYK color modes. When the file is of a different type or color mode, the status code 415 will be returned.
Transparency and Customizable Binarization
This endpoint returns an image where the background is removed, and the foreground remains with varying levels of transparency, allowing for smoother edges and more natural blending when placed over different backgrounds. Additionally, this unique output provides developers with the flexibility to binarize the result—transforming it into a binary mask—by setting a custom transparency threshold according to their specific use case. A binary mask is an image where pixels are either fully visible (foreground) or fully transparent (background), commonly used in visual generative AI and image processing pipelines. This capability enables seamless integration into workflows that require clear separation between subject and background, while still offering control over how strict this separation should be.
Below is a simple Python script to demonstrate how you can binarize the output image from the API. This allows you to set your own threshold to determine which areas are considered "foreground" and which are "background."
from PIL import Image
import numpy as np
# Load the image (the output from the API)
image = Image.open('output_image.png').convert('RGBA')
# Convert to numpy array
data = np.array(image)
# Define your threshold (0-255, where 255 is fully opaque)
threshold = 128
# Apply the threshold: if alpha > threshold, set to fully opaque (255), otherwise transparent (0)
data[:, :, 3] = np.where(data[:, :, 3] > threshold, 255, 0)
# Create a new Image from the modified array
binarized_image = Image.fromarray(data)
# Save or display
binarized_image.save('binarized_output.png')
binarized_image.show()
```
Request
- Base URL: https://engine.prod.bria-api.com/v2/image/edit
- URL: https://engine.prod.bria-api.com/v2/image/edit/remove_background
- Auth: API key in header api_token
Request body
Response
Successful operation (Synchronous Success)
Changes
- info
added the new optional request property
- info
- warning
deleted the
headerrequest parameterapi_token - info
api tag
Editingadded - info
api tag
v2 endpointsremoved
- warning