rembg is a free, open source photo & video editors project written in Python and released under MIT. It has 24,796 GitHub stars, 2,423 forks and 3 open issues, and was last pushed 11 days ago. On this registry it ranks #4 of 22 tracked projects in Photo & Video Editors, with 5 head-to-head comparisons available.

What is rembg?

Rembg is an MIT-licensed Python tool for removing image backgrounds, usable as a CLI, a Python library, an HTTP server, or a Docker container, and aimed at developers, designers, and automated image pipelines that need background removal without depending on a hosted service.

What it is

Rembg lives in the Python image-processing ecosystem, tagged with the topics background-removal, image-processing, and python. It wraps ONNX segmentation models — u2net, u2netp, sam, and custom models loaded by path — behind four consistent surfaces: the rembg command-line tool, an importable Python library, an HTTP server with an OpenAPI page at /api, and a Docker container. It is distributed on PyPI, requires Python 3.11 or newer, and carries an MIT licence. The repository shows 24,796 stars, 2,423 forks, and only 3 open issues.

The concrete problem it solves is cut-out work. Instead of sending every image to a per-call cloud service or masking subjects by hand, Rembg runs the segmentation model on the operator's own machine and writes a transparent PNG. It handles one file, an entire folder, a watched folder, or a live HTTP request against the same model set. When a hosted model is genuinely wanted, the tool can also route to the withoutBG cloud API as a model choice rather than as a replacement for its own local inference.

Key capabilities

  • CLI subcommands i, p, s, b, d, and m cover single files, folder batch processing, the HTTP server, an RGB24 pixel binary stream, ahead-of-time model downloads, and migration of models from the legacy ~/.u2net directory.
  • Model selection with -m and extra parameters passed as JSON with -x, including SAM prompting with a point prompt and custom models via {"model_path": "~/.u2net/u2net.onnx"}.
  • Post-processing flags: -om returns only the mask, -a applies alpha matting, and -dc removes color fringing from soft edges.
  • Batch folders with rembg p path/to/input path/to/output, plus watch mode through rembg p -w to process new and changed files automatically.
  • HTTP server via rembg s --host 0.0.0.0 --port 7000 --log_level info, exposing /api/remove?url= and multipart uploads, with --no-ui to cut idle CPU from the Gradio interface.
  • Unix-friendly stdin and stdout handling: curl -s http://input.png | rembg i > output.png, and a default output path of input.out.png when none is given.
  • Install extras that match the hardware: rembg[cpu], rembg[gpu], and rembg[rocm], each combinable with the cli extra.

Who uses it and how

  • Designers and photographers clearing a single asset from the terminal with rembg i input.png output.png, or piping a remote image through stdin.
  • Content pipelines running rembg p over a folder of product or editorial images, and using -w so new files are processed as they land.
  • Backend teams standing up rembg s as an internal service, calling /api/remove from application code and consulting the Gradio UI or /api docs for manual checks.
  • Python developers embedding the library directly and choosing a model per job, including SAM for prompted selections.
  • Operations teams deploying the Docker container for repeatable environments, on NVIDIA hosts with CUDA and cudnn-devel or AMD hosts with onnxruntime-rocm.

Getting started

Install from PyPI with pip install "rembg[gpu,cli]" for library plus command line, or rembg[cpu] and rembg[rocm] for the corresponding hardware paths, then run rembg i input.png output.png. For a service deployment, start rembg s --host 0.0.0.0 --port 7000; the README also documents a Docker container.

How it compares

Unlike hosted background-removal services such as the PhotoRoom API and withoutBG, which charge per call and require images to leave the host, Rembg runs inference locally under the MIT licence with no per-image cost. The two are not mutually exclusive: passing -m withoutbg with a key in WITHOUTBG_API_KEY or the -x extras routes a request to that cloud API, so Rembg can sit in front of a hosted service as well as replace the need for one.

When to use it — and when not to

A self-hoster must operate Python 3.11 or newer and the right ONNX runtime, and the GPU path adds NVIDIA CUDA plus cudnn-devel or the onnxruntime-rocm package installed per AMD's documentation, with rembg[gpu] failing on hosts that lack them. Teams without a GPU box, or without anyone willing to run a Python service, are better served by a hosted API. Note also that model downloads consume disk, and that the provided README excerpt is truncated mid-section, so the full server and Docker documentation should be read at the source before planning a deployment.

project readme (upstream, from github) — read inline

Rembg is a tool to remove image backgrounds. It can be used as a CLI, Python library, HTTP server, or Docker container.

License Hugging Face Spaces Streamlit App Open in Colab RepoMapr


danielgatis%2Frembg | Trendshift

Sponsors

PhotoRoom PhotoRoom Remove Background API
https://photoroom.com/api

Fast and accurate background remover API

If this project has helped you, please consider making a donation.

Requirements

python: >=3.11, <3.14

Installation

Choose one of the following backends based on your hardware:

CPU support

pip install "rembg[cpu]" # for library
pip install "rembg[cpu,cli]" # for library + cli

GPU support (NVIDIA/CUDA)

First, check if your system supports onnxruntime-gpu by visiting onnxruntime.ai and reviewing the installation matrix.

If your system is compatible, run:

pip install "rembg[gpu]" # for library
pip install "rembg[gpu,cli]" # for library + cli

Note: NVIDIA GPUs may require onnxruntime-gpu, CUDA, and cudnn-devel. See #668 for details. If rembg[gpu] doesn't work and you can't install CUDA or cudnn-devel, use rembg[cpu] with onnxruntime instead.

GPU support (AMD/ROCm)

ROCm support requires the onnxruntime-rocm package. Install it by following AMD's documentation.

Once onnxruntime-rocm is installed and working, install rembg with ROCm support:

pip install "rembg[rocm]" # for library
pip install "rembg[rocm,cli]" # for library + cli

Usage as a CLI

After installation, you can use rembg by typing rembg in your terminal.

The rembg command has these subcommands:

  • i - single files
  • p - folders (batch processing)
  • s - HTTP server
  • b - RGB24 pixel binary stream
  • d - download models ahead of time
  • m - migrate models from the legacy ~/.u2net directory

You can get help about the main command using:

rembg --help

You can also get help for any subcommand:

rembg <COMMAND> --help

rembg i

Used for processing single files.

Remove background from a remote image:

curl -s http://input.png | rembg i > output.png

Remove background from a local file:

rembg i path/to/input.png path/to/output.png

Omit the output path (writes .out.png next to the input):

rembg i path/to/input.png
# → path/to/input.out.png

If stdout is redirected (e.g. rembg i input.png > out.png), the output is written to stdout instead.

Specify a model:

rembg i -m u2netp path/to/input.png path/to/output.png

Return only the mask:

rembg i -om path/to/input.png path/to/output.png

Apply alpha matting:

rembg i -a path/to/input.png path/to/output.png

Remove color fringing from soft edges:

rembg i -dc path/to/input.png path/to/output.png

See Color decontamination for what this does.

Pass extra parameters (SAM example):

rembg i -m sam -x '{ "sam_prompt": [{"type": "point", "data": [724, 740], "label": 1}] }' examples/plants-1.jpg examples/plants-1.out.png

Pass extra parameters (custom model):

rembg i -m u2net_custom -x '{"model_path": "~/.u2net/u2net.onnx"}' path/to/input.png path/to/output.png

Use the withoutBG cloud API:

Get 50 free credits with signup. Sample results.

export WITHOUTBG_API_KEY=sk_...
rembg i -m withoutbg path/to/input.png path/to/output.png

Or pass the key via extras:

rembg i -m withoutbg -x '{"api_key":"sk_..."}' path/to/input.png path/to/output.png

rembg p

Used for batch processing entire folders.

Process all images in a folder:

rembg p path/to/input path/to/output

Watch mode (process new/changed files automatically):

rembg p -w path/to/input path/to/output

rembg s

Used to start an HTTP server.

rembg s --host 0.0.0.0 --port 7000 --log_level info

For complete API documentation, visit: http://localhost:7000/api

Disable the Gradio UI (reduces idle CPU usage):

rembg s --no-ui

Remove background from an image URL:

curl -s "http://localhost:7000/api/remove?url=http://input.png" -o output.png

Remove background from an uploaded image:

curl -s -F file=@/path/to/input.jpg "http://localhost:7000/api/remove" -o output.png

rembg b

Process a sequence of RGB24 images from stdin. This is intended to be used with programs like FFmpeg that output RGB24 pixel data to stdout.

rembg b <width> <height> -o <output_specifier>

Arguments:

Argument Description
width Width of input image(s)
height Height of input image(s)
output_specifier Printf-style specifier for output filenames (e.g., output-%03u.png produces output-000.png, output-001.png, etc.). Omit to write to stdout.

Example with FFmpeg:

ffmpeg -i input.mp4 -ss 10 -an -f rawvideo -pix_fmt rgb24 pipe:1 | rembg b 1280 720 -o folder/output-%03u.png

Note: The width and height must match FFmpeg's output dimensions. The flags -an -f rawvideo -pix_fmt rgb24 pipe:1 are required for FFmpeg compatibility.

Usage as a Library

Input and output as bytes:

from rembg import remove

with open('input.png', 'rb') as i:
    with open('output.png', 'wb') as o:
        input = i.read()
        output = remove(input)
        o.write(output)

Input and output as a PIL image:

from rembg import remove
from PIL import Image

input = Image.open('input.png')
output = remove(input)
output.save('output.png')

Input and output as a NumPy array:

from rembg import remove
import cv2

input = cv2.imread('input.png')
output = remove(input)
cv2.imwrite('output.png', output)

Force output as bytes:

from rembg import remove

with open('input.png', 'rb') as i:
    with open('output.png', 'wb') as o:
        input = i.read()
        output = remove(input, force_return_bytes=True)
        o.write(output)

Batch processing with session reuse (recommended for performance):

from pathlib import Path
from rembg import remove, new_session

session = new_session()

for file in Path('path/to/folder').glob('*.png'):
    input_path = str(file)
    output_path = str(file.parent / (file.stem + ".out.png"))

    with open(input_path, 'rb') as i:
        with open(output_path, 'wb') as o:
            input = i.read()
            output = remove(inpu

readme truncated — read the full docs on github

Frequently asked questions

Is rembg free to use?

rembg is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does rembg do?

Rembg is a tool to remove images background

What is rembg written in?

rembg is primarily written in Python. Its source is publicly available at https://github.com/danielgatis/rembg, and it has 24,796 GitHub stars.