Repository navigation
Add preprocessor: blur detection, deskew, denoise - #10
Merged
Merged
Conversation
khadijja1
approved these changes
Sep 7, 2026
Khubaib8281
approved these changes
Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.