Online background removers are handy, but they upload your photos, add watermarks or charge per image. You can get the same quality, or better, for free on your own PC.
Modern open models like BiRefNet and BRIA RMBG-2.0 cut out hair, fur and product edges cleanly, and they run offline on almost any GPU, even on a CPU.
This guide shows three ways to remove image backgrounds locally:
- the rembg command line, for one image or a whole folder in seconds;
- Python code, for your own scripts and apps;
- a ComfyUI workflow, for visual control, batch jobs and replacing the background in the same graph.
It also covers which model to pick, how to get clean edges without colour halos, licence rules for commercial work, and fixes for common errors. Versions are checked in November 2026: rembg 2.0.87 and ComfyUI-RMBG 3.3.1.
- Fastest:
pip install "rembg[cpu,cli]"(or[gpu,cli]for NVIDIA) thenrembg i input.jpg output.png. - Whole folder:
rembg p -dc input_folder output_folder. - Best general model:
bria-rmbg(rembg default, about 1 GB) orbirefnet-general. Portraits:birefnet-portrait. Anime:isnet-anime. - Colour halo around hair? Add
-dc. Hair cut off? Try-vm(ViTMatte). - ComfyUI: install ComfyUI-RMBG by 1038lab from the Manager; models download to
ComfyUI/models/RMBG/. - Commercial use: RMBG-2.0 needs a paid BRIA licence. BiRefNet models are a safer free choice; always check the model card.
Why Remove Backgrounds Locally?
- Privacy: product shots, client photos and personal pictures never leave your computer.
- No limits: process thousands of images without credits, subscriptions or watermarks.
- Full resolution: many free web tools shrink the output; local tools keep your original size.
- Automation: batch whole folders or plug background removal into your own app or ComfyUI pipeline.
Hardware needs are modest. Small models like u2netp run fine on a CPU. BiRefNet and RMBG-2.0 work on a CPU too, but an NVIDIA GPU makes them much faster, which matters for batches.
Which Background Removal Model to Use
| Model (rembg name) | Best for | Speed | Notes |
|---|---|---|---|
bria-rmbg |
Best all-round quality | Slower (about 1 GB, runs at 1024×1024) | rembg’s default. BRIA licence: paid agreement for commercial use |
birefnet-general |
General objects and people | Medium | Excellent edges; -fp16 variant about 30% faster on CUDA |
birefnet-general-lite |
Same, on weaker hardware | Fast | Slightly softer detail |
birefnet-portrait |
People, hair | Medium | Pair with -dc or -vm |
birefnet-massive |
Tricky, varied images | Medium | Trained on a large dataset |
isnet-general-use |
General use | Fast | Good middle ground |
isnet-anime |
Anime and illustrations | Fast | Made for anime characters |
u2net / u2netp / silueta |
Speed, low memory | Very fast | Older; blockier edges |
u2net_cloth_seg |
Clothing masks | Fast | Splits upper, lower and full body clothing |
sam |
Pick an object with a click point | Medium | Needs a prompt point or box |
A simple choice: start with the default. If you need commercial-safe output or faster batches, switch to birefnet-general.
Method 1: rembg Command Line
rembg is a free, MIT-licensed tool with a command line, a Python library and a small web server. It needs Python 3.11 to 3.13.
- Create a virtual environment (keeps things tidy):
python -m venv rembg-envthen activate it (rembg-env\Scripts\activateon Windows,source rembg-env/bin/activateon Mac or Linux). - Install rembg for your hardware:
- CPU:
pip install "rembg[cpu,cli]" - NVIDIA GPU:
pip install "rembg[gpu,cli]"(check your CUDA version against the onnxruntime-gpu install matrix first) - AMD GPU (ROCm):
pip install "rembg[rocm,cli]"
- CPU:
- Remove a background:
rembg i photo.jpg photo-cutout.png. The first run downloads the model. - Pick a model with
-m:rembg i -m birefnet-general photo.jpg out.png - Batch a folder:
rembg p input_folder output_folder. Add-wto watch the folder and process new files automatically.
# single image, default model
rembg i product.jpg product.png
# portrait with clean hair edges
rembg i -m birefnet-portrait -dc portrait.jpg portrait.png
# only output the black-and-white mask
rembg i -om photo.jpg mask.png
# whole folder with colour decontamination
rembg p -dc ./photos ./cutouts
Always save as PNG or WebP. JPG has no transparency, so the background turns black or white.
Run it as a local web app
rembg s --host 127.0.0.1 --port 7000 starts a small server with a browser UI and an HTTP API, which is handy for non-technical teammates on the same PC. Keep it on 127.0.0.1 unless you understand the security risks of exposing it on your network.
Get Clean Edges: -dc, -a and -vm
The model decides what is foreground. The edge mode decides how soft pixels along hair, fur and fabric are handled.
| Flag | What it does | Use when | Cost |
|---|---|---|---|
| (none) | Plain cutout | Hard edges: products, logos, cars, screenshots | Free |
-dc |
Removes background colour bleeding into edges | Green, blue or coloured halo around hair. Safe for batches | Negligible |
-a |
Alpha matting re-estimates the edge shape | Hair strands cut off or stair-stepped edges | Slow |
-vm |
ViTMatte neural matting | Same as -a, recovers more fine strands |
Slow, about 110 MB extra download |
-ppm |
Makes the mask fully binary | Pixel-perfect hard edges for icons | Free |
The rembg docs recommend trying -dc first with newer models (bria-rmbg, BiRefNet, isnet), and only reaching for -a or -vm if the edge shape itself is wrong. Do not combine -ppm with -dc.
Method 2: Python Script
Use rembg as a library in your own tools. Create a session once and reuse it, so the model loads only one time:
from pathlib import Path
from PIL import Image
from rembg import remove, new_session
session = new_session("birefnet-general")
src, dst = Path("photos"), Path("cutouts")
dst.mkdir(exist_ok=True)
for f in src.glob("*.jpg"):
out = remove(Image.open(f), session=session)
out.save(dst / (f.stem + ".png"))
print("done", f.name)
Models are stored in ~/.rembg/models/ by default. Set the REMBG_HOME environment variable to keep them on another drive.
Put a white background behind the cutout
cut = remove(Image.open("product.jpg"), session=session)
bg = Image.new("RGBA", cut.size, (255, 255, 255, 255))
bg.alpha_composite(cut)
bg.convert("RGB").save("product-white.jpg", quality=95)
That is all most online shops need for marketplace listings.
Method 3: ComfyUI With ComfyUI-RMBG
If you already use ComfyUI, the ComfyUI-RMBG custom node pack by 1038lab is the most complete option.
It supports RMBG-2.0, BiRefNet (including HR, matting and the Lucida fine-tune for transparent objects, text and logos), BEN2, INSPYRENET, SAM2 and SAM3 text-prompted segmentation, clothes and face segmentation, and even video background removal. New to ComfyUI? Start with our ComfyUI beginner guide.
- Open ComfyUI Manager (see how to install ComfyUI Manager), click Custom Nodes Manager, search
ComfyUI-RMBGand install the one by 1038lab. - Install its requirements with ComfyUI’s own Python. For the Windows portable build, from the
ComfyUI_windows_portablefolder:python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-RMBG\requirements.txt - Restart ComfyUI and refresh the browser.
- Build the workflow:
Load Image>RMBG(orBiRefNet) node >Save Image. Pick the model in the node; most models download toComfyUI/models/RMBG/on first use. - Tune the node: adjust mask blur and offset for softer or tighter edges, and choose the background output (transparent or a colour).
- Batch: swap
Load Imagefor a folder or batch loader node and queue once.
Manual model folders, if auto-download fails: RMBG-2.0 goes in ComfyUI/models/RMBG/RMBG-2.0, BiRefNet in ComfyUI/models/RMBG/BiRefNet, SAM2 in ComfyUI/models/sam2 and SAM3 in ComfyUI/models/sam3. Each node has an unload_model toggle that frees VRAM after the job.
The Windows desktop ComfyUI app can crash after installing requirements; the node’s README suggests setting PYTHONUTF8=1 and reinstalling. If the nodes show red after restart, see our ComfyUI import failed fix.
Replace the Background With a Colour or New Scene
- Solid colour: use the background colour option in the ComfyUI-RMBG node, or the Python snippet above.
- New photo: in ComfyUI, composite the cutout (image plus mask) over a second loaded image with an image composite node.
- AI-generated scene: feed the mask into an inpainting or edit model to paint a new background that matches the lighting. Qwen-Image Edit models are great at this.
- Bigger output: upscale the final image; see our ComfyUI upscale guide or the simpler AI image upscaling guide.
Only edit photos you own or have permission to use, and never use these tools to create misleading images of real people.
Licences and Commercial Use
| Item | Licence | Commercial use |
|---|---|---|
| rembg (the tool) | MIT | Yes |
BRIA RMBG-2.0 (bria-rmbg) |
BRIA licence | Needs a paid agreement with BRIA |
| BiRefNet models | Check each model card (the Lucida fine-tune is MIT) | Usually yes; verify |
| Other models (u2net, isnet, SAM) | Their own licences | Check the linked source |
rembg’s docs stress that model weights carry their own licences, separate from rembg’s MIT licence. For client or shop work, BiRefNet is the usual safe default.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Black or white background instead of transparent | Saved as JPG | Save as PNG or WebP |
| Coloured halo around hair | Background colour bleeding into edges | Add -dc |
| Hair strands cut off | Mask too hard | Use birefnet-portrait with -vm or -a |
| Wrong object kept | Several subjects in the photo | Use sam with a click point, or SAM2/SAM3 in ComfyUI |
| GPU not used | CPU onnxruntime installed, or CUDA mismatch | Install rembg[gpu] matching your CUDA, uninstall plain onnxruntime |
| Very slow | Large default model on CPU | Use birefnet-general-lite, isnet-general-use or u2netp |
pip install fails |
Python too new or too old | Use Python 3.11 to 3.13 |
| ComfyUI-RMBG nodes red or missing | Requirements not installed in ComfyUI’s Python | Run the pip command with python_embeded and restart |
| Model download fails in ComfyUI | Network or Hugging Face access | Download manually into ComfyUI/models/RMBG/<model> |
FAQ
What is the best free background remover I can run offline?
rembg with BRIA RMBG-2.0 or BiRefNet gives results that match paid web tools, all offline. For commercial use, prefer BiRefNet.
Can I remove backgrounds without a GPU?
Yes. rembg runs on a CPU. Use lighter models like u2netp or birefnet-general-lite for speed.
How do I remove the background from many images at once?
Run rembg p input_folder output_folder, or use a batch loader in ComfyUI.
Can it handle hair and fur?
Yes. Use birefnet-portrait or bria-rmbg with -dc, and -vm when fine strands matter.
Can I remove the background from a video?
ComfyUI-RMBG 3.3 added a VRMBG video node for frame-consistent matting. Note that the VRMBG-3.0 model must be downloaded manually under BRIA’s licence terms.
Where does rembg store its models?
In ~/.rembg/models/. Change it with the REMBG_HOME environment variable.




