danielgatis
/
rembg
Rembg is a tool to remove images background
Rembg is a tool to remove image backgrounds. It can be used as a CLI, Python library, HTTP server, or Docker container.
Sponsors
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, andcudnn-devel. See #668 for details. Ifrembg[gpu]doesn't work and you can't install CUDA orcudnn-develā¦
We can run gpu version on Google colab
!pip install rembg[gpu]
If you want to run the script on your local machine without a gpu, you will need to install 2 packages. If you have OpenCV, you can use it instead of Pillow.
pip install rembg
pip install -U Pillow
from rembg import remove
from PIL import Image
input_path = 'input.jpg' # input image path
output_path = 'output.png' # output image path
input = Image.open(input_path) # load image
output = remove(input) # remove background
output.save(output_path) # save image
Incredibly easy!!!



Top comments (1)
Nice one... Hope to try it out