2026-06-07 01:07:29 +08:00
2026-06-07 01:07:29 +08:00
2026-04-09 01:51:57 +08:00
2026-04-09 02:10:05 +08:00
2026-04-09 01:51:57 +08:00
2026-04-09 01:51:57 +08:00

Crop White Backgrounds from Photos

This Python script automatically crops white (or near-white) backgrounds from scanned or photographed images. It handles scanner dust and tiny specks by using a density-based approach, ensuring only the real photo content is kept.

All cropped images are saved into a cropped folder inside the input folder.


Features

  • Crop white/near-white backgrounds from scanned photos.
  • Ignores scanner dust and tiny specks.
  • Supports batch processing using folders or glob patterns.
  • Saves all outputs in a cropped folder automatically.
  • Adjustable threshold, padding, and min-density parameters.

Requirements

Install dependencies via pip:

pip install -r requirements.txt

Usage:


# Crop a single image
python crop_white_background.py photo/image1.jpg

# Crop a single image with custom parameters
python crop_white_background.py photo/image1.jpg --threshold 220 --padding 20 --min-density 30

# Crop all JPEG images in a folder using glob pattern
python crop_white_background.py photo/*.jpg

# Crop all images in a folder using --folder
python crop_white_background.py --folder photo/
S
Description
A simple python code for removing/cropping the excess white background from the photos scanned from the scanner.
Readme
3.9 MiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%