Page Extractor
Extracts a page from a photo, and warps it to a rectangular image using skimage.
Features
- Remove margin clutter from photos of pages, usually improved document processing.
- GroundingDINO detection model integration.
- SAM 2.1
- Customizable text prompt, e.g. to "receipt." or "invoice."
Getting Started
Prerequisites
- Python 3.10 or higher
Installation
Installing PyTorch Dependencies
Before installing pageextractor, install PyTorch:
pip install torch==2.4.1 torchvision==0.19.1 --extra-index-url https://download.pytorch.org/whl/cu124
Installation options
pip install -U git+https://github.com/UG-Team-Data-Science/pageextractor.git
Or:
git clone https://github.com/UG-Team-Data-Science/pageextractor && cd pageextractor
pip install -e .
Usage
from PIL import Image
from matplotlib import pyplot as plt
from pageextractor import PageExtractor
img = Image.open('example.png')
model = PageExtractor(sam_type='sam2.1_hiera_tiny', device='cuda')
mask, polygon, cropped = model.extract_page(img)
_, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(30, 15))
ax0.imshow(img)
ax1.imshow(img)
ax1.plot(*polygon[[0,1,2,3,0]].T, 'r:')
ax1.imshow(1-mask, cmap='Blues', alpha=0.8 - 0.8*mask)
ax2.imshow(cropped)
Examples
Photo of a book page, unfortunately centerfold and page block are included
Photo of a letter
Acknowledgments
This project is based on/used the following repositories:
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pageextractor-0.1.10.tar.gz
(10.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pageextractor-0.1.10.tar.gz.
File metadata
- Download URL: pageextractor-0.1.10.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f417fdd81e1adf4e85164f1bd28cc327dd5c4d5fc70cc735275fe7f668e892dd
|
|
| MD5 |
6bcdc1dc04655f2d4beff4dc1dfce122
|
|
| BLAKE2b-256 |
3182033ff4a86d293ac61e1fac44415bc91bd859ef47277a39643f66d083a0d7
|
File details
Details for the file pageextractor-0.1.10-py3-none-any.whl.
File metadata
- Download URL: pageextractor-0.1.10-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
276002acebf1ce893ed167b804b7daa83071fc5f9254fe71438c8f71cbfd8b9d
|
|
| MD5 |
1dabf005147b27765742d8d4340ce966
|
|
| BLAKE2b-256 |
e13ec744d399728c95ca0ea94b6a46ec13ca123560fa5ff1ddb654b16629ba2f
|