This small utility removes image backgrounds using MediaPipe Selfie Segmentation and saves transparent PNGs.
Requirements
- Python 3.8+
- See
requirements.txtfor dependencies.
Install
Open PowerShell and run:
python -m pip install -r requirements.txtUsage examples
Process a single image and save to a specific output path:
python scripts/remove_bg.py input.jpg --output out.png --transparentProcess a folder (glob) and save outputs in a directory:
python scripts/remove_bg.py "images\*.jpg" --outdir results --transparent --keep-filenameComposite on white background instead of transparency:
python scripts/remove_bg.py portrait.jpg --outdir results --bg-color 255,255,255Notes
mediapipeworks best on portraits/selfie-style photos. For general scenes results may vary.- If you want a more heavy-duty model (U2Net / rembg) consider using
rembg, but that requires model downloads and larger dependencies.
License
MIT