Remove photo background by Python

GeoSense ✅
Nov 28, 2022

Here is a simple way to remove the background of an image.


python: >3.7, <3.11


CPU support:

pip install rembg

GPU support:

pip install rembg[gpu]

Main code here:

Source photo by Author
from rembg import remove
from PIL import Image

input= "source.jpg"
out = "out.png"
Im =
Out = remove(Im)
Output photo




GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️