doc-preproc
Lightweight, zero-dependency, non-destructive document image quality diagnosis, adaptive preprocessing, and exact 2D coordinate mapping for Python (>=3.10).
Design Principles
- Pure Python core, zero required runtime dependencies: Operates on a lightweight
GrayImage2D grid (0..255) with seamless duck-typed support for 2D grayscale or 3D RGBnumpyarrays when passed in. - Non-destructive by default: Never mutates input images and never applies destructive hard binarization.
- No-op fast path: Clean images with negligible skew, healthy contrast, and even lighting incur zero pixel transforms (
is_noop=True, identityAffineTransform2D). - Exact reversible geometry: Every geometric transform returns an exact 2x3
AffineTransform2Dwithforward(x, y)andinverse(x', y')mapping between original and preprocessed coordinates. - Strict safety boundary: Performs deterministic signal processing only—no OCR inference, no generative super-resolution/image synthesis, and no network calls.
Installation
Install in editable mode from a local checkout:
pip install -e .
Quick Start
from doc_preproc import GrayImage, compute_crop_plan, diagnose, preprocess
# Construct from nested lists (or pass a 2D/3D numpy array directly)
image = GrayImage.filled(120, 80, value=250.0)
# 1. Inspect image quality
report = diagnose(image)
print(report.skew_angle_deg, report.blur_score, report.contrast_score)
# 2. Run adaptive, non-destructive preprocessing
result = preprocess(image, profile="receipt")
print(result.is_noop, result.applied_transforms)
# Map a point from preprocessed coordinates back to original image coordinates
orig_x, orig_y = result.transform.inverse(50.0, 30.0)
# 3. Compute an optimal local re-read crop plan with exact coordinate transform
plan = compute_crop_plan(
bbox=(10.0, 20.0, 90.0, 45.0),
image_size=(image.width, image.height),
estimated_char_height_px=14.0,
target_char_height_px=28.0,
)
print(plan.scale_factor, plan.output_size)
Public API
GrayImage: Row-major 2D grayscale container withfrom_nested,from_any,to_nested,copy, and bilinear sampling.AffineTransform2D: Composable 2x3 affine matrix (identity,translation,scale,rotation,forward,inverse,invert,compose).diagnose(image, config=None) -> QualityReport: Computesskew_angle_deg,blur_score,contrast_score,illumination_unevenness,estimated_char_height_px,aspect_ratio, and advisoryunreadable_flag/unreadable_reasons.preprocess(image, profile="receipt"|"invoice"|"crop", config=None) -> PreprocessResult: Runs diagnosis and applies only needed transforms (deskew,illumination_normalization,contrast_normalization), returning(image, report, transform, applied_transforms, is_noop).compute_crop_plan(...) -> CropPlan&apply_crop_plan(image, plan) -> GrayImage: Computes padded crop bounds, optimal scale factor, and exact coordinate transform for local re-read regions.
Running Tests
PYTHONPATH=src python -m unittest discover -s tests -v
Metadata
Release files for doc-preproc 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| doc_preproc-0.1.0.tar.gz | 18.2 kB | Without provenance | Details for doc_preproc-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| doc_preproc-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for doc_preproc-0.1.0-py3-none-any.whl |
Total release size: 32.3 kB
Release files / doc_preproc-0.1.0.tar.gz
| Download URL | doc_preproc-0.1.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35242b37b06efd496bcd3aaf793b46e740ed364d8e1f85ada902b77296b66bde
|
|
BLAKE2b-256 checksum How to use checksums |
62a05c9b13b1470d3e2c5c470244965e0a7d1dd09ce88e4175347e109e78803a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Release files / doc_preproc-0.1.0-py3-none-any.whl
| Download URL | doc_preproc-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c18079f8b8051f35a8ae1d76d83bd683b4773027a25262d647134fa68f7af87
|
|
BLAKE2b-256 checksum How to use checksums |
3f80fd0fbedbf7d47acdde51561e566487279d04d4a87cd76251a4b5a8263233
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.5
|
Security for doc-preproc 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.