Repository navigation
fix: exclude cumulative redactions from later OCR boxes (1.2.2) - #107
Merged
Merged
Conversation
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.
Later OCR passes can return a page-sized box for a footer digit even though most of the input has been erased. Clip each later-stage layout to the largest rectangle inside its original box that avoids every previously erased pixel; discard fully covered layouts. Accumulate actual masks across arbitrary stage counts, restore resized coordinates before clipping, and rebuild structured output after correction.
Exports
clip_layouts_to_unmasked_areafor consumers that orchestrate their own OCR calls. It accepts the same inclusive mask coordinates as Pillow redaction; layout bounds remain half-open. Changed boxes discard stale polygons while retaining text and raw diagnostics. Equal-area results prefer top, then left. Coordinate compression avoids scanning page pixels.The captured DeepSeek-OCR page-4 response had box
(0,0,2474,3497)for4. Its actual masks produce(0,3158,2474,3497), which retains the complete real digit at(1228,3247,1249,3278)without overlapping erased pixels. This is a fallback for invalid OCR geometry and may discard text in smaller remnants.Bumps both package version declarations from 1.2.1 to 1.2.2 and documents cumulative masks and custom-pipeline integration. pdf-craft's separately orchestrated asynchronous OCR path must explicitly adopt the helper in a subsequent change; this PR does not change that repository or deploy services.
Validation: all 36 lightweight tests pass, including captured geometry, inclusive boundaries, four-stage cumulative masking, image rescaling, per-call isolation, structured output, and 150 seeded cases compared with exhaustive rectangle search (including reversed mask order). Pylint: 10.00/10;
git diff --checkpasses. No CUDA or paid OCR calls required.