Rembg removes backgrounds from images using ONNX segmentation models. It runs as a terminal command, a Python package, an HTTP server, or a container image.
Overview
Rembg is an image utility that segments the foreground and strips the background from photos and graphics. It relies on downloadable ONNX models that are fetched on first use and cached locally, with several architectures tuned for general photos, portraits, clothing, and other subjects.
You can invoke it from the command line for single files or whole folders, including a watch mode that picks up new images in a directory. Subcommands also start an HTTP service for URL or upload-based processing, emit binary mask streams for FFmpeg pipelines, prefetch models, and migrate older model directories.
Optional processing steps address soft edges: default masking, color decontamination to reduce halos from colored backgrounds, alpha matting to refine uncertain boundaries, and ViTMatte for finer hair detail at higher compute cost. CPU inference is the baseline; separate installs add NVIDIA CUDA or AMD ROCm acceleration when compatible runtimes are present.
As a Python library it accepts bytes, PIL images, or NumPy arrays and can reuse sessions for batches. Container images exist for CPU-only and custom CUDA builds, and integrations can call external hosted removal APIs when local models are not desired.
Key features
- CLI for single files and folders
- Python library with batch sessions
- HTTP server with upload and URL APIs
- Multiple ONNX background models
- Alpha matting and edge decontamination
- Docker images for CPU and CUDA
- FFmpeg RGB24 stream integration
- Optional cloud API backends
Use cases
- Cutting products out of catalog photos
- Batch-processing image folders
- Automating cutouts in video pipelines
- Serving background removal over HTTP
- Portrait and hair-detail masking