Engineering · Neural Networks
How BiRefNet Removes Photo Backgrounds with ONNX Runtime
BiRefNet finds the subject in a photo. AssetHUD runs it on your CPU, turns its prediction into transparency, and saves a PNG you can place over a new background. Here’s what happens at each step and how to get a cleaner cutout.
Updated
Published by AssetHUD
What BiRefNet does
Imagine cutting a bouquet out of a photo. The centers of the flowers are easy to keep. The gaps between stems and the thin edges of the petals take more care. BiRefNet looks at the whole image to locate the foreground, then uses finer image information to reconstruct its outline.
The research calls this task dichotomous image segmentation. It means separating the image into foreground and background. The model produces a mask with a value at each pixel. In a mask preview, white means keep, black means hide, and gray can become partial transparency at an edge. The gray values are estimates. Glass, smoke, and motion blur can still be difficult because the subject and background are visually mixed in the source photo.
In the original architecture, a localization module finds the subject from the overall scene. A reconstruction module uses that context and finer image details to recover boundaries. That combination matters when the shape is clear from a distance but the edge needs a closer look. Read the original BiRefNet paper.
How a photo becomes a transparent PNG
ONNX is the model file format. ONNX Runtime runs the model. AssetHUD bundles a BiRefNet ONNX model and uses ONNX Runtime’s CPU execution provider to run it locally. After initial online setup, you can process a local photo without uploading it. See the ONNX Runtime execution provider documentation.
- Prepare the photo. AssetHUD resizes a copy to 1024 × 1024 pixels for the High Precision model and converts its red, green, and blue values to the scale the model expects. Photos with an edge longer than 3,840 pixels are scaled down proportionally first.
- Predict the foreground. BiRefNet returns a mask. Image detail that disappears during the resize can be hard for the model to recover.
- Apply the mask at the working image size. AssetHUD scales the mask back up and multiplies it by the input’s alpha channel, which stores each pixel’s opacity. This produces a cutout with transparent background pixels and partially transparent edges.
- Clean the edges and export. AssetHUD refines the alpha channel and reduces leftover background color around the edge, then saves the result as a PNG. A 2,400 × 1,600 photo can yield a 2,400 × 1,600 cutout even though the mask was predicted from a smaller square input.
When to use Fast or High Precision
| Mode | Start here when | Check the result for |
|---|---|---|
| Fast (Silueta) | You need a rough preview, or the subject has a simple outline and clear contrast. | Missing thin edges, small holes, or narrow gaps. |
| High Precision (BiRefNet) | You’re cutting out fur, petals, thin handles, or other detailed shapes for a final design. | Halos, leftover background color, or missing fine details. |
Fast uses a 320 × 320 model input in AssetHUD. High Precision uses a larger model and generally needs more CPU time and working memory. The first cutout can also include model loading. Later cutouts can reuse the loaded model, so compare both modes on your own computer if speed matters.
Try both modes on the same photo
- Open a photo in Studio. Use a subject with an easy edge and a difficult one, such as a mug with a visible handle or a plant with thin leaves.
- Choose Fast and click Remove Background. In Split view, zoom in and compare the outline and any gaps.
- Switch to High Precision and click Remove Background again. Inspect the same areas. Keep the result that looks best at the size you’ll actually use it.
- Save a PNG and place it on both a light and a dark background. A fringe that blends into one backdrop can stand out on the other.
How to fix common cutout problems
- A small subject loses detail. Crop the source closer around the subject while leaving room around its edges. More of the model’s input is then spent on the part you want to keep.
- Part of the background comes along. Try a clearer crop or a source shot with more separation between the subject and background. If a precise outline matters, clean up the mask by hand in your editor.
- A colored halo shows up after export. Check the cutout on the final backdrop. If the old wall or green screen tinted fine strands in the original, the cutout can still need manual cleanup.
- The cutout has a solid background after saving. Check the export format. PNG supports transparency. A JPG will flatten it.
Follow the cutout-to-Figma walkthrough to see the PNG used in a design, or read the transparent PNG guide for the export steps.