Skip to content

Add preprocessor: blur detection, deskew, denoise - #10

Merged
Khubaib8281 merged 1 commit into
mainfrom
feat/preprocessor
Sep 7, 2026
Merged

Khubaib8281 merged 1 commit into
mainfrom
feat/preprocessor

Conversation

@M-O-J-U

@M-O-J-U M-O-J-U commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds preprocessor.py: loads an image, checks blur (Laplacian variance), deskews small rotation angles, and denoises.

Which module(s) does it touch?

docling_pk/preprocessor.py, docling_pk/init.py (new).

How did you test it?

Tested directly against real document photos (CNIC and certificates, including deliberately blurry samples). Adaptive thresholding was in an earlier version and was removed after an A/B test showed it consistently lowered OCR confidence on every sample tested. Blur threshold (35, Laplacian variance) was calibrated from 4 real samples, not guessed.

Edge cases handled:

Missing file raises FileNotFoundError. Unreadable file raises ValueError. Image below the sharpness threshold raises TooBlurryError with a clear message instead of processing an image that will only produce garbage OCR output. Deskew is confirmed to fail against cluttered or textured backgrounds, documented as a known v1 limitation, not silently hidden.

Checklist:

  • Tests added or updated
  • Docstrings on all new public functions
  • No unused imports
  • README updated if public API changed (no public API change, internal module)
  • Lead Engineer has reviewed and approved before submitting to director (no separate Lead on this project currently, Khubaib and Khadija are aware and approved proceeding solo)

Note: this PR was pushed earlier but the GitHub PR itself was never opened. This is the actual fix for the current CI failure (docling_pk.preprocessor missing from main). Recommend reviewing and merging this before PR #9 (Copilot's auto-fix), since that PR may not be aware this real, tested code already exists.

@Khubaib8281
Khubaib8281 merged commit c8b34b1 into main Sep 7, 2026
1 check failed
@Khubaib8281
Khubaib8281 deleted the feat/preprocessor branch September 7, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants