Guide · Open source
How to use rembg: remove image backgrounds from the terminal or Python
Updated · written with AI from the project's own documentation and checked against our catalogue data
Rembg is an open-source tool that removes the background from an image and leaves the main subject on a transparent background. It can run as a command-line tool, a Python library, a local HTTP server or a Docker container. This guide shows you how to install it with pip, process single files and whole folders, and call it from Python so you can start removing backgrounds on your own machine.
Quick start
- 1Check your Python version. Confirm you have Python 3.11, 3.12 or 3.13 and that pip is available.
- 2Install rembg. Run pip install "rembg[cpu,cli]" to get the library and command-line tool with the CPU backend.
- 3Try a single file. Run rembg i with an input path and an output path, then open the PNG to check the transparent background.
- 4Adjust the model or edges if needed. Use -m to choose a different model, or add -a or -dc to refine soft edges.
- 5Batch a folder. Run rembg p on your input folder and output folder to process many images at once.
- 6Call it from Python or start the server. Use from rembg import remove in your code, or run rembg s to serve requests over HTTP.
Check the requirements before you install rembg
Rembg is written in Python and the README lists Python >=3.11 and <3.14 as the requirement. Installation is done with pip, so you need pip available as well.
If you have an NVIDIA or AMD GPU, the README says GPU setup may be difficult. It describes a GPU path that needs onnxruntime-gpu, CUDA and cudnn-devel, or onnxruntime-rocm for AMD, and it suggests falling back to the CPU version if those cannot be installed.
- Python 3.11, 3.12 or 3.13
- pip
- Optional: a supported GPU setup if you want GPU acceleration
python: >=3.11, <3.14Install rembg with the CPU version and CLI
The README's CPU install gives you both the library and the command-line tool. Use the cli extra if you want the rembg command in your terminal.
For library use only, the README also lists pip install "rembg[cpu]". The GPU variants are rembg[gpu] and rembg[rocm], and they use the same pattern with a cli extra.
pip install "rembg[cpu,cli]"Remove the background from a single image with the CLI
The rembg i subcommand processes single files. Give it an input path and an output path. If you omit the output path, rembg writes a file named <input_stem>.out.png next to the input. If you redirect stdout, the result goes to stdout instead.
Other options in the README include -m to pick a model, -om to return only the mask, -a for alpha matting and -dc for color decontamination of soft edges.
- Pick a model with -m, for example u2netp
- Return only the mask with -om
- Refine soft edges with alpha matting using -a
- Reduce color fringing with -dc
rembg i path/to/input.png path/to/output.pngProcess a whole folder in batch
Use rembg p to process every image in a folder. Add -w to run watch mode, which processes new or changed files automatically.
Batch mode is the usual choice for product photos or any set of images that need the same treatment.
rembg p path/to/input path/to/outputUse rembg from Python code
The library exposes a remove function. It accepts bytes, a PIL image or a NumPy array, and returns the result in a matching form. Pass force_return_bytes=True if you always want bytes back.
Import it with from rembg import remove. The README examples use PIL for image files and OpenCV (cv2) for NumPy arrays, so install those packages if you follow those examples.
from rembg import remove
from PIL import Image
input = Image.open('input.png')
output = remove(input)
output.save('output.png')Run rembg as a local HTTP server
The rembg s subcommand starts an HTTP server. The README says full API documentation is at /api on the server address. The server includes a Gradio UI, and --no-ui turns it off to reduce idle CPU use.
You can then send an image with curl, either by URL or as an uploaded file, so the images stay on your own machine.
- Use --host and --port to set the address
- Use --no-ui if you do not need the web interface
rembg s --host 0.0.0.0 --port 7000 --log_level infoProcess video frames with FFmpeg
The rembg b subcommand reads a stream of RGB24 pixel data from stdin, which is the format FFmpeg can output. You give it the width and height, and an output filename pattern. The README warns that the width and height must match FFmpeg's output dimensions, and that the FFmpeg flags shown are required.
- Replace the width and height with your video's dimensions
- Use a printf-style pattern such as output-%03u.png for numbered files
ffmpeg -i input.mp4 -ss 10 -an -f rawvideo -pix_fmt rgb24 pipe:1 | rembg b 1280 720 -o folder/output-%03u.pngWhat people use it for
- Preparing product photos with a transparent background
- Batch processing a folder of photos for a designer or creator
- Adding background removal to a Python program with the remove function
- Running a local server so images are not uploaded to a website
- Extracting and cutting out frames from video by piping FFmpeg output into rembg b
Frequently asked questions
Is rembg free to use?
Rembg is released under the MIT licence, according to the project's listing. The licence allows you to use the code, but you should read the licence text for the full terms before you rely on it in a product.
Which Python version does rembg need?
The README lists Python >=3.11 and <3.14. If you use Python 3.10 or 3.14 or later, the project's stated requirement is not met, so install a supported version first.
How do I install rembg?
Run pip install "rembg[cpu,cli]" to get the CPU version with the command-line tool. Use the library-only extra rembg[cpu] if you only need Python code.
Can I use rembg with an NVIDIA or AMD GPU?
The README describes GPU options for NVIDIA through rembg[gpu] and for AMD through rembg[rocm]. It says GPU setup may be difficult and that CUDA, cudnn-devel or onnxruntime-rocm may be needed, and it suggests the CPU version if those cannot be installed.
What are the alternatives to rembg?
The project's analysis lists U-2-Net, backgroundremover and withoutbg as comparable projects. The README also mentions a withoutBG cloud API option you can call from rembg with -m withoutbg, which requires an API key.
Does rembg have a graphical app?
The README describes rembg as a CLI, Python library, HTTP server and Docker container. It includes a Gradio UI only as part of the server, so it is not a standard point-and-click desktop app.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Rembg suits developers who want background removal inside a Python program, and creators who need to batch a folder of images on their own machine. It is less suited to people who want a point-and-click app, or to anyone on a Python version outside 3.11 to 3.13 or with a GPU setup they cannot install. In those cases, a hosted service or one of the listed alternatives may be a better fit.
Install options & downloads