← Back to archive

Repo of the Day

danielgatis/rembg: Rembg is a tool to remove images background

Published: Sep 18, 2026

Open repository ↗

Rembg is a tool to remove images background

Summary

rembg is a Python-based tool that removes backgrounds from images using local ONNX neural network models. It exposes the same core function (rembg.remove) through four interfaces: a CLI, an importable library, an HTTP server, and a Docker container. The README recommends Python 3.11 to 3.13 and ships with several interchangeable models, edge-handling modes, and optional CPU, NVIDIA CUDA, and AMD ROCm backends.

What it is useful for

rembg fits anywhere a pipeline needs a clean cutout of a foreground subject without sending data to a third-party service by default. Practical cases documented in the README include product photography, portraits, anime characters, cloth parsing, and batch jobs over a folder of images. Engineers can swap models depending on the trade-off they want: bria-rmbg is the default and produces soft alpha but is the largest local model at roughly 1.02 GB; u2netp and silueta are smaller and faster but have blockier edges; birefnet-portrait is tuned for portraits; isnet-anime is tuned for anime; sam accepts point prompts for selective segmentation; and withoutbg is a cloud API backend for when local inference is not viable.

Edge quality is a separate decision. The README describes four modes: the default (naive), -dc for color decontamination when soft edges pick up a halo from a colored background, -a for alpha matting when the mask shape itself is wrong, and -vm for ViTMatte when fine hair or fur detail matters more than runtime.

How engineers can use it

Installation depends on the backend. The README's documented commands are:

pip install "rembg[cpu]"          # library only
pip install "rembg[cpu,cli]"      # library + CLI
pip install "rembg[gpu,cli]"      # NVIDIA CUDA; onnxruntime-gpu compatibility must be checked first
pip install "rembg[rocm,cli]"     # AMD ROCm; requires onnxruntime-rocm

As a CLI, the README shows basic usage:

rembg i path/to/input.png path/to/output.png
rembg i -m u2netp path/to/input.png path/to/output.png
rembg i -dc path/to/input.png path/to/output.png
rembg p path/to/input path/to/output         # batch over a folder
rembg p -w path/to/input path/to/output      # watch mode
rembg s --host 0.0.0.0 --port 7000           # HTTP server

As a library, the README's example uses a reused session for batch performance:

from pathlib import Path
from rembg import remove, new_session

session = new_session()
for file in Path('path/to/folder').glob('*.png'):
    with open(file, 'rb') as i, open(file.parent / f"{file.stem}.out.png", 'wb') as o:
        o.write(remove(i.read(), session=session))

Inputs and outputs work as raw bytes, PIL Image objects, or NumPy arrays via OpenCV.

Docker images are published (docker run danielgatis/rembg i ...); the NVIDIA CUDA image is not prebuilt because it requires cudnn-devel and the README links to issue #668 for the build steps. Models download automatically on first use into ~/.rembg/models/ (override with REMBG_HOME), and the rembg m command migrates files from the older ~/.u2net/ directory.

Limitations called out in the README: Python must be 3.11–3.13 (governed by onnxruntime support), the NVIDIA Docker image is large (~11 GB) and must be built locally, alpha matting can fail to converge on some images and falls back to decontamination, and model licenses are independent of rembg's MIT license. The README explicitly notes that RMBG-2.0 weights require a paid agreement for commercial use, and the withoutbg cloud backend sends images to a third party with a 20 MB upload limit. For full configuration and advanced flags, refer to the README and the linked USAGE.md.