Batch product-photo cleaner for e-commerce catalogs. Drop a folder of product photos in, get clean white-background images out. No manual work per image.
Built around BiRefNet (current SOTA open-source background removal) with a small Python wrapper for the composite + enhance + scoring steps. Runs locally on Apple Silicon (MPS), CUDA, or CPU.
Sample inputs above (Pexels, CC0): a transparent-glass lightbulb on a chalkboard, a wrench pair on shadowed white, and a cluttered tool board. The lightbulb case is the hardest of the three — transparent glass on a dark patterned background — and the cutout preserves the glass globe and filament cleanly.
For each image in the input folder:
- Background removal — BiRefNet (
basemode = SOTA,fastmode = ~3x faster). - White composite — pure
#FFFFFFbehind the cutout, no shadow, no gradient. - Enhance — unsharp mask + light contrast boost. Geometry is never modified.
- Quality score — alpha-edge sharpness per image, written to
log.json. Anything below threshold is flaggedneeds_reviewso you can spot the 2–5% of images that need a manual look.
Resumable: outputs in OUTPUT_DIR are skipped on rerun.
Requires Python 3.10–3.12 (BiRefNet weights and transparent-background don't ship Python 3.13/3.14 wheels yet).
git clone https://github.com/Bambushu/photoclean-pipeline
cd photoclean-pipeline
python3.12 -m venv .venv
.venv/bin/pip install -r requirements.txtFirst run downloads the BiRefNet weights (~400 MB) automatically.
.venv/bin/python scripts/photoclean.py path/to/input path/to/outputOptional --mode fast for ~3x throughput at slightly lower edge quality (useful for catalog drafts).
Tested on M5 Pro (MPS), 800x600 input images:
| mode | first image (warmup) | per image after |
|---|---|---|
| base | ~2.5s | ~0.5s |
| fast | ~1.5s | ~0.2s |
200 images = under 2 minutes. 2,000 images = under 20 minutes.
- Reflective chrome / mirror finishes: BiRefNet sometimes carves into reflective surfaces. Inspect
needs_reviewflags. - Multi-object scenes you want cropped to one object: this preserves all foreground objects. Add a center-crop or single-object selector if you need just the hero.
- Wireframe / fine mesh / chain link: edge accuracy drops. Use
--mode baseand budget for manual touch-up on these. - You need shadow under the product: this strips shadows entirely. Add a synthetic shadow pass after if your catalog template needs one.
- Remove.bg is solid but $0.20–$0.50 per image at the 2,000+ scale, plus you're locked into their API quality decisions.
rembg(isnet-general-use) is free but BiRefNet beats it on hard edges (transparent glass, fine wires, fur, hair).- Photoshop actions still need a human in the loop for foreground selection on busy backgrounds.
BiRefNet is current SOTA on open background-removal benchmarks and runs locally with no per-image cost. The tradeoff is the model is heavier (~400 MB) and requires a venv setup.
MIT. Sample images in samples/before/ are from Pexels (CC0, free for commercial use, no attribution required).
Built by Maikel Slomp (@Bambushu). Available for catalog batch jobs at any scale.
