This blog introduces tools used to remove background of portrait photos. Required tools are listed below:
- Rembg: remove background by using u2net model
- MacOS Preview: polish photos from Rembg and crop photos
- A simple Python script: change the background from transparent to any color (e.g, white).
You could follow instructions on Github to install Rembg. Note that I fail to install Rembg on my MacBook Pro with M1 chip. I suggest to install Rembg on a Linux machine.
Once you complete the installation, you could easily remove background by Rembg. To avoid redundant jump between websites, I copy the example commands of Rembg to here.
Remove the background from a remote image
curl -s http://input.png | rembg > output.png
Remove the background from a local file
rembg -o path/to/output.png path/to/input.png
Remove the background from all images in a folder
rembg -p path/to/input path/to/output
You could use “Instant Alpha” button to polish your photo.
from PIL import Image