How to easily remove image backgrounds locally with Rembg
A part of my job involves creating slides for presentations (for clients, events, etc.), which led me down this path: finding a great tool for background removal from an image.
So, why does this even matter?
Well, your mileage may vary, but the way I approach these presentations is through a ton of visuals. I believe it helps capture the audience’s attention better. While doing this, I constantly come across images that I wish were available as an alternate version, with a transparent background.
Let me explain with an example. Imagine presenting to a few executives at a customer’s office, and you get to slide 10. It has three beautiful images that are each telling a collective story, BUT they all have different background colors. One might be black, one red, and the other yellow. This can be jarring to the eye and put people off, especially those with an attention to detail. If you have a color theme running throughout your presentation deck (let’s say a white background on all slides, blue fonts, and black borders), you ideally want your pictures to have the same background effect to harmonize with the main deck.
Hopefully, that explains why this tool became a lifeline for my day job. Let’s get into the tool itself now.
I scanned the internet and found a few different ways to do this, but the most reliable way to remove backgrounds without paying a single penny was this GOAT of a tool that I found: Rembg. It has a simple CLI that I use to get the job done. I’ll show you how below.
Rembg is a tool to remove image backgrounds. It can be used as a CLI, Python library, HTTP server, or Docker container.
I use macOS. If you are on a Mac as well, the commands below will help you set it up:
pip3 install "rembg[cpu,cli]"
After the installation please run the below commands to confirm its installed successfully along with instructions:
rembg --version
# rembg, version 2.0.84
rembg --help
# Usage: rembg [OPTIONS] COMMAND [ARGS]...
# Options:
# --version Show the version and exit.
# --help Show this message and exit.
# Commands:
# b for a byte stream as input
# d download models
# i for a file as input
# m migrate models from the legacy ~/.u2net directory
# p for a folder as input
# s for a http server
As you can see from the instructions above, there are multiple commands to get the job done. I use i because it handles single file input/output, but you could choose p for batch processing. For example, if you run a large e-commerce website, you could upload entire folders of images through this workflow to harmonize their backgrounds before publishing them to your site.
I started with just one image, but realized it forced Rembg to download a model before running the task. Once I completed that task, I decided to run d to download all the models for future use.
rembg i /Users/mbilal/Desktop/b300.jpg /Users/mbilal/Desktop/b300.png
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/bria-rmbg-2.0.onnx' to file '/Users/mbilal/.rembg/models/bria-rmbg/bria-rmbg.onnx'.
100%|██████████████████████████████████████| 1.02G/1.02G [00:00<00:00, 161GB/s]
rembg d
No models specified, downloading all models
Downloading model: birefnet-general
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-general-epoch_244.onnx' to file '/Users/mbilal/.rembg/models/birefnet-general/birefnet-general.onnx'.
100%|████████████████████████████████████████| 973M/973M [00:00<00:00, 318GB/s]
Downloading model: birefnet-general-lite
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-general-bb_swin_v1_tiny-epoch_232.onnx' to file '/Users/mbilal/.rembg/models/birefnet-general-lite/birefnet-general-lite.onnx'.
100%|████████████████████████████████████████| 224M/224M [00:00<00:00, 788GB/s]
Downloading model: birefnet-portrait
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-portrait-epoch_150.onnx' to file '/Users/mbilal/.rembg/models/birefnet-portrait/birefnet-portrait.onnx'.
100%|███████████████████████████████████████| 973M/973M [00:00<00:00, 2.67TB/s]
Downloading model: birefnet-dis
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-DIS-epoch_590.onnx' to file '/Users/mbilal/.rembg/models/birefnet-dis/birefnet-dis.onnx'.
100%|███████████████████████████████████████| 973M/973M [00:00<00:00, 1.24TB/s]
Downloading model: birefnet-hrsod
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-HRSOD_DHU-epoch_115.onnx' to file '/Users/mbilal/.rembg/models/birefnet-hrsod/birefnet-hrsod.onnx'.
100%|███████████████████████████████████████| 973M/973M [00:00<00:00, 2.27TB/s]
Downloading model: birefnet-cod
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-COD-epoch_125.onnx' to file '/Users/mbilal/.rembg/models/birefnet-cod/birefnet-cod.onnx'.
100%|███████████████████████████████████████| 973M/973M [00:00<00:00, 2.65TB/s]
Downloading model: birefnet-massive
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/BiRefNet-massive-TR_DIS5K_TR_TEs-epoch_420.onnx' to file '/Users/mbilal/.rembg/models/birefnet-massive/birefnet-massive.onnx'.
100%|████████████████████████████████████████| 973M/973M [00:00<00:00, 312GB/s]
Downloading model: isnet-anime
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/isnet-anime.onnx' to file '/Users/mbilal/.rembg/models/isnet-anime/isnet-anime.onnx'.
100%|████████████████████████████████████████| 176M/176M [00:00<00:00, 122GB/s]
Downloading model: dis_custom
Error downloading model: model_path is required
Downloading model: isnet-general-use
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/isnet-general-use.onnx' to file '/Users/mbilal/.rembg/models/isnet-general-use/isnet-general-use.onnx'.
100%|████████████████████████████████████████| 179M/179M [00:00<00:00, 478GB/s]
Downloading model: sam
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/sam_vit_b_01ec64.encoder.onnx' to file '/Users/mbilal/.rembg/models/sam/sam_vit_b_01ec64.encoder.onnx'.
100%|███████████████████████████████████████| 359M/359M [00:00<00:00, 1.37TB/s]
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/sam_vit_b_01ec64.decoder.onnx' to file '/Users/mbilal/.rembg/models/sam/sam_vit_b_01ec64.decoder.onnx'.
100%|██████████████████████████████████████| 16.5M/16.5M [00:00<00:00, 164GB/s]
Downloading model: silueta
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/silueta.onnx' to file '/Users/mbilal/.rembg/models/silueta/silueta.onnx'.
100%|██████████████████████████████████████| 44.2M/44.2M [00:00<00:00, 190GB/s]
Downloading model: u2net_cloth_seg
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net_cloth_seg.onnx' to file '/Users/mbilal/.rembg/models/u2net_cloth_seg/u2net_cloth_seg.onnx'.
100%|███████████████████████████████████████| 176M/176M [00:00<00:00, 1.06TB/s]
Downloading model: u2net_custom
Error downloading model: model_path is required
Downloading model: u2net_human_seg
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net_human_seg.onnx' to file '/Users/mbilal/.rembg/models/u2net_human_seg/u2net_human_seg.onnx'.
100%|████████████████████████████████████████| 176M/176M [00:00<00:00, 402GB/s]
Downloading model: u2net
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net.onnx' to file '/Users/mbilal/.rembg/models/u2net/u2net.onnx'.
100%|████████████████████████████████████████| 176M/176M [00:00<00:00, 457GB/s]
Downloading model: u2netp
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2netp.onnx' to file '/Users/mbilal/.rembg/models/u2netp/u2netp.onnx'.
100%|█████████████████████████████████████| 4.57M/4.57M [00:00<00:00, 36.9GB/s]
Downloading model: bria-rmbg
Downloading model: ben_custom
Error downloading model: model_path is required
The custom failures are normal. Because we did not specify a path for custom models Rembg skipped them. The standard models did download successfully.
I checked the official GitHub documentation, and it turns out this is by design, those ONNX models are set to download automatically the first time you fire up the tool.
Local ONNX models are automatically downloaded on first use and saved under ~/.rembg/models/ (see Where models are stored). The withoutbg model is a cloud API backend and does not download a local model.
Model list:
The default model, bria-rmbg, is outstanding. It is a state-of-the-art model. At ~1GB, it is also the largest model on the list. It’s considered a bit slower than some of the smaller models, but the latency and size penalty is totally worth it when you consider the amazing outputs it churns out. It is built on the BiRefNet architecture and contains 0.2B parameters, which is relatively lightweight compared to massive LLMs. It is available for non-commercial use via the link above; for commercial purposes, be sure to read the official docs and follow their instructions.
Let’s run a few images through the Rembg CLI to analyze the outputs. For this demo, we’ll stick to the Bria model, as I find it to be the most effective of the ones I’ve tested.
Image 1: Leo (perhaps the Greatest of All Time).

rembg i messi.webp messi-rembg.png

That is ABSOLUTELY AMAZING. The way it cuts out the edges never fails to impress me.
Image 2: A nostalgic still from The Phantom (1996)

rembg i phantom.jpeg phantom-rembg.png

Besides the almost unavoidable text wrapped over the left arm, the result is quite amazing again.
Image 2: An iconic frame from Terminator 2

rembg i t2.jpg t2-rembg.png

ABSOLUTELY STUNNING result, to say the least.
This brings us to the end of what has been a really exciting post for me to write. I hope you enjoyed it too, and I hope this proves useful to some of you reading. Thanks for your time!