danielgatis/rembg
Rembg is a tool to remove images background
What it solves
Rembg removes the background from images, turning them into cutouts that can be used for product photos, portraits, or any design work. It tackles the messy edges that often come with background removal—like colored halos around hair or fur—by offering different edge treatment modes. It also provides multiple ways to run the tool so you can integrate it into your own scripts, web services, or batch workflows.
How it works
Rembg uses pre-trained machine learning models (in ONNX format) to segment the subject from the background. You can choose from several models tuned for different subjects: general objects, humans, anime characters, clothes, and more. The models are downloaded automatically on first use and cached on your machine. After the model produces a mask, Rembg can apply optional post-processing:
- Naive mode (default): directly uses the mask to cut out the subject, leaving semi-transparent edges as-is.
- Color decontamination (
-dc): estimates and replaces the background color that bleeds into soft edge pixels, removing colored fringes. - Alpha matting (
-a): refines the mask shape itself, re-estimating coverage with a closed-form solver to recover fine details like wispy hair. - ViTMatte (
-vm): instead of solving, it uses a neural network to predict per-pixel alpha, giving even finer detail at the cost of a larger model download and slower run time.
The tool is packaged in four forms: a command-line interface (CLI), a Python library, an HTTP server, and a Docker container. The CLI supports single files, folder batches, and even reading raw RGB24 frames from FFmpeg for video frame processing. The Python library offers a simple remove() function that accepts bytes, PIL images, or NumPy arrays. The HTTP server exposes a REST API for remote calls, and the Docker image lets you run it in any container environment.
Who it's for
Rembg is aimed at developers, designers, and automation engineers who need background removal in their projects. It suits anyone who wants to process individual images or large folders, embed background removal into an application via Python, or run a background-removal service via HTTP. The multiple deployment options make it accessible whether you work locally, in the cloud, or in a containerized environment.
Highlights
- Four usage modes: CLI, Python library, HTTP server, and Docker container.
- Pluggable models: supports many ONNX models like u2net, u2netp, isnet, BiRefNet, SAM, and more (including cloud APIs from withoutBG and AtlasCloud).
- Edge quality options: choose between fast naive cuts, color decontamination for halos, alpha matting for fine detail, or ViTMatte for even finer hair.
- Batch and watch mode: process entire folders and watch for new files with the
-wflag. - HTTP API: simple REST endpoint for removing backgrounds from URLs or uploaded files.
- RGB24 stream support: works with FFmpeg to process video frames as a pixel stream.
- Easy installation: choose CPU, NVIDIA CUDA, or AMD ROCm backends with different pip extras.
Related
- Project
- Project
- Project
- Project