Hugging Face background removal output formats (2027)

Bria.ai

Hugging Face background removal output formats (2027)

Updated 2026-12-01

TL;DR

  • Most return a matte: RMBG 3.0 and RMBG-2.0 return a single-channel 8-bit matte. White is the subject, black is the background, grey is partial transparency.

  • Two steps to a cutout: Resize the matte to the photo and call Pillow's putalpha, as the cards show.

  • Some return a finished image: BEN2 returns a foreground image that the card saves as foreground.png.

  • Hard mask on demand: Threshold the matte. Bria's docs give a threshold of 128 on the alpha channel.

  • Best for production: RMBG 3.0 through the Bria API returns an image with transparency, so there is no matte step.

Which background removal model on Hugging Face is best for production? Part of the answer is what the model hands back. This guide lists what five models return and how to get a transparent PNG from each. Bria wrote it and makes the RMBG models.

What do Hugging Face background removal models return?

They return one of three things: a soft matte, a binary or probability mask, or a finished image with the background removed.

A matte holds one opacity value per pixel. A finished image already carries that value as its alpha channel. Your code needs to know which one it gets, because a matte needs one more step before you can place the subject on a new background.

Which models return a matte and which return a cutout?

RMBG 3.0, RMBG-2.0, BiRefNet and MODNet return mattes or masks, and BEN2 returns a finished foreground.

  • Model: RMBG 3.0; What the card code produces: Single-channel 8-bit matte, resized with Lanczos; Next step: putalpha on the source image

  • Model: RMBG-2.0; What the card code produces: Single-channel 8-bit grayscale alpha matte; Next step: resize, then putalpha

  • Model: BiRefNet; What the card code produces: Sigmoid probability map at 1024 x 1024; Next step: resize, then putalpha

  • Model: MODNet (Transformers.js); What the card code produces: Alpha matte saved as mask.png; Next step: apply as alpha in your canvas code

  • Model: BEN2; What the card code produces: Foreground image, saved as foreground.png; Next step: none

Source: model cards on Hugging Face, read 2026-12-02. MODNet is the Xenova port under Apache-2.0.

How do you turn a matte into a transparent PNG?

Resize the matte to the original image size and add it as the alpha channel with `putalpha`.

Once you have the matte as an image file, four Pillow lines finish the job. This snippet needs Pillow (pip install pillow), a photo named photo.jpg and a matte named matte.png in the same folder:

from PIL import Image

image = Image.open("photo.jpg").convert("RGB")
matte = Image.open("matte.png").convert("L").resize(image.size)
image.putalpha(matte)
image.save("cutout.png")

The RMBG-2.0 and BiRefNet cards produce the matte the same way: resize to image.size, then putalpha.

The Pillow documentation says putalpha "adds or replaces the alpha layer" and that the new layer must be mode "L" or "1". BiRefNet's README uses the same pattern, and RMBG 3.0's card calls cutout.putalpha(matte).

Why do these models return a matte and not a hard mask?

A matte keeps partial transparency, so hair, fur and glass edges blend into a new background.

The RMBG 3.0 card says grey marks "partial transparency at hair, fur, glass and motion blur", and describes "a true 8-bit alpha matte with anti-aliased edges, not a hard binary mask". RMBG-2.0's card says the non-binary output lets developers define custom thresholds for their use case. A hard mask throws that information away.

How do you get a binary mask from a matte?

Pick a threshold and set every alpha value above it to 255 and every other value to 0.

  • Matte alpha value: 255; Meaning: Subject, white; After threshold 128: 255

  • Matte alpha value: 129 to 254; Meaning: Partial transparency, grey; After threshold 128: 255

  • Matte alpha value: 1 to 128; Meaning: Partial transparency, grey; After threshold 128: 0

  • Matte alpha value: 0; Meaning: Background, black; After threshold 128: 0

Source: RMBG 3.0 card for the meaning of white, black and grey, and the Bria API reference for the rule that alpha above the threshold becomes 255 and every other value becomes 0. Read 2026-12-02.

  • Threshold 128: the value in the Bria docs example, where alpha above 128 becomes opaque.

  • Higher threshold: keeps fewer soft edge pixels.

  • Lower threshold: keeps more of them.

  • Keep the matte: store the soft version and threshold only at the point of use.

Bria's API reference shows the NumPy version of this step on an RGBA image.

What size does the matte come back at?

Model input is fixed, and the cards resize the result back to the photo.

The RMBG-2.0 and BiRefNet code resizes the input to 1024 x 1024 and the mask back to image.size. The RMBG 3.0 card calls result.convert("L").resize(source.size, Image.LANCZOS). Pillow's putalpha expects an alpha layer the same size as the image, so keep the resize step.

What does the Bria API return?

It returns an image where the background is removed and the foreground keeps varying levels of transparency.

The API reference lists JPEG, PNG and WEBP input in RGB, RGBA or CMYK. The default sync: false returns a status URL to poll, or you pass webhook_url. The model parameter takes RMBG2 or RMBG3. In Bria's benchmark, RMBG 3.0 ranked first of 6 models, with an average rank of 1.51 across 234 hard images (benchmark post). RMBG 3.0 costs $0.018 per image on the Bria API, checked 2026-12-02 on the pricing page.

Which output format should you choose?

Choose the format your pipeline can consume without extra code.

  • Choose the Bria API if you want a transparent PNG back and a commercial license included.

  • Choose a matte model (RMBG 3.0 weights, RMBG-2.0, BiRefNet) if your code already composites with alpha. Check each card's license first.

  • Choose BEN2 if you want a finished foreground image from MIT weights.

  • Choose MODNet in Transformers.js for browser canvas work with portraits.

Related posts

FAQs

It depends on the model. RMBG 3.0 and RMBG-2.0 return a single-channel 8-bit matte. BiRefNet returns a sigmoid probability map that the card turns into a mask. MODNet in Transformers.js returns a matte saved as mask.png, and BEN2 returns a finished foreground image. Read the usage code on each card to see the exact output. Always check the output type before you write the compositing code.

An alpha matte is a grayscale image with one opacity value per pixel. White marks the subject, black marks the background, and grey marks partial transparency such as hair or fur edges. The RMBG 3.0 card describes it as an 8-bit matte you can use directly as the alpha channel, or threshold if you need a binary mask. A hard mask keeps only two values.

Resize the matte to the size of the original image, then add it as the alpha layer with Pillow's putalpha method, and save as PNG. The RMBG-2.0 and BiRefNet cards both do this. Pillow's documentation says the new layer must be mode L or 1. Keep the resize step, because the layer must match the image size. The BiRefNet README uses the same call.

Choose a threshold and set every alpha value above it to 255 and everything else to 0. Bria's API reference shows a NumPy example that uses a threshold of 128 on the alpha channel of an RGBA image. Keep the soft matte and apply the threshold only where you need a hard mask, because thresholding discards partial transparency. The Bria docs example keeps the RGB channels and changes only alpha.

Follow us on social media

discord
Social media logo
Social media card
Social media logo
Social media card
Social media logo