Skip to content

fix: exclude cumulative redactions from later OCR boxes (1.2.2) - #107

Merged
Moskize91 merged 2 commits into
mainfrom
fix/cumulative-ocr-redaction
Oct 25, 2026
Merged

Moskize91 merged 2 commits into
mainfrom
fix/cumulative-ocr-redaction

Conversation

@Moskize91

Copy link
Copy Markdown
Owner

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_area for 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) for 4. 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 --check passes. No CUDA or paid OCR calls required.

@Moskize91
Moskize91 merged commit 603a6fa into main Oct 25, 2026
1 check passed
@Moskize91
Moskize91 deleted the fix/cumulative-ocr-redaction branch October 25, 2026 16:54
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.

1 participant