Remove photo background by Python

GeoSense ✅
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:

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

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

Enjoy!

--

--

GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️ https://www.tnmthai.com/medium