Remove photo background by Python
Nov 28, 2022
Here is a simple way to remove the background of an image.
Requirements
python: >3.7, <3.11
Installation
CPU support:
pip install rembg
GPU support:
pip install rembg[gpu]
Main code here:
from rembg import remove
from PIL import Image
input= "source.jpg"
out = "out.png"
Im = Image.open(input)
Out = remove(Im)
Out.save(out)
Enjoy!