Skip to content

Bambushu/photoclean-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

photoclean

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.

before / after

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.

What it does

For each image in the input folder:

  1. Background removal — BiRefNet (base mode = SOTA, fast mode = ~3x faster).
  2. White composite — pure #FFFFFF behind the cutout, no shadow, no gradient.
  3. Enhance — unsharp mask + light contrast boost. Geometry is never modified.
  4. Quality score — alpha-edge sharpness per image, written to log.json. Anything below threshold is flagged needs_review so you can spot the 2–5% of images that need a manual look.

Resumable: outputs in OUTPUT_DIR are skipped on rerun.

Install

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.txt

First run downloads the BiRefNet weights (~400 MB) automatically.

Use

.venv/bin/python scripts/photoclean.py path/to/input path/to/output

Optional --mode fast for ~3x throughput at slightly lower edge quality (useful for catalog drafts).

Performance

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.

When this isn't the right tool

  • Reflective chrome / mirror finishes: BiRefNet sometimes carves into reflective surfaces. Inspect needs_review flags.
  • 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 base and 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.

Why BiRefNet over Remove.bg / rembg / Photoshop actions

  • 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.

License

MIT. Sample images in samples/before/ are from Pexels (CC0, free for commercial use, no attribution required).

Author

Built by Maikel Slomp (@Bambushu). Available for catalog batch jobs at any scale.

About

Batch product-photo cleaner: BiRefNet background removal + white composite + enhance, for e-commerce catalogs. Local, no per-image API cost.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages