Skip to content

feat(easyocr): stretch a faint page to full contrast before detection - #112

Merged
stephen-masters merged 2 commits into
mainfrom
feat/lift-faint-ink
Nov 16, 2026
Merged

stephen-masters merged 2 commits into
mainfrom
feat/lift-faint-ink

Conversation

@stephen-masters

Copy link
Copy Markdown
Contributor

Closes #110 (brief 023, Stage 1).

What

  • imaging.lift_faint_ink: a page whose darkest thousandth of pixels, over its central three quarters, is lighter than grey level 45 and at least 30 below the paper is stretched with ImageOps.autocontrast(cutoff=1). Any other page is left alone.
  • imaging.detector_input: what an EasyOCR reader is handed. The file's own path for an ordinary page, exactly as before; PNG bytes for a TIFF (as before) and for a faint page.
  • easyocr, easyocr-hy and tools/dump_layout_spans.py all go through it, so the span cache reads a page as the shipped backend does.
  • evaluation/ocr/registers.csv re-emitted; the engines page describes the step.

Why

A book photographed in grey reaches the detector with its ink sixty or seventy levels below the paper. The detector breaks words apart and drops letters, and no recogniser behind it can put them back. Abovyan vol. 1 is such a scan, and the register easyocr-hy loses to hye-paddle by most. The measurements behind the rule are in #109.

Measured

Read in the environment the published table was read in (see #111), the rule fires on three registers and nothing else moves:

Register Word recall Character similarity Pages up / down
Abovyan vol. 1 0.794 → 0.835 0.900 → 0.921 9 / 1
ASE vol. 2 0.911 → 0.917 0.971 → 0.975 7 / 2
Medical encyclopedia 0.951 → 0.956 0.960 → 0.953 7 / 2
Mean of seventeen 0.892 → 0.895 0.955 → 0.956

The other fourteen rows are unchanged to the last digit. Baronian's Azgayin jojer, black ink on toned paper and the one set a blanket stretch hurt, is not stretched and reads identically, span for span. Mshak (not in the table) goes from 0.804 to 0.814.

Not a clean win everywhere: the medical encyclopedia trades 0.007 of character similarity for 0.005 of word recall. Abovyan is still 0.075 behind hye-paddle; this is the scan's share of that gap, not all of it.

Checked

  • 525 tests pass (the Vision tests need macOS's ocrmac and are skipped here, as on main). New tests pin which drawn pages are faint: black on white, toned paper with black ink, a sparse title page and a blank grey leaf are all left alone, and a dark binding at the edge does not pass for ink.
  • Site lint and build pass.

Follow-up

The model card's pipeline column quotes the same three registers and will want the new figures once this is released.

🤖 Generated with Claude Code

stephen-masters and others added 2 commits November 16, 2026 21:32
Brief 023, issue #110. A book photographed in grey can arrive with its
ink sixty or seventy levels below the paper; the detector then breaks
words apart and drops letters, and no recogniser behind it can put them
back. imaging.lift_faint_ink stretches a page whose darkest thousandth
of pixels, over its central three quarters, is lighter than grey level
45 and at least 30 below the paper, and leaves every other page alone.
The rule keys on the ink, not the paper: a register of black ink on
toned paper lost a little word recall to the same stretch.

Both EasyOCR backends and the span-cache tool now take the page through
imaging.detector_input, which returns the file's own path for an
ordinary page, so it reaches the detector exactly as before.

Co-authored-by: Yvette Mankerian <yvettekm@gmail.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The rule fires on three of the seventeen registers and the table moves
only there: Abovyan 0.794 to 0.835 word recall, the encyclopedia up a
little on both measures, the medical encyclopedia up 0.005 on word
recall and down 0.007 on character similarity. The other fourteen rows
are unchanged to the last digit, read from the same cached spans. The
engines page describes the step and what it costs.

Co-authored-by: Yvette Mankerian <yvettekm@gmail.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying tetrak with  Cloudflare Pages  Cloudflare Pages

Latest commit: 44d84aa
Status: ✅  Deploy successful!
Preview URL: https://f07a6550.tetrak.pages.dev
Branch Preview URL: https://feat-lift-faint-ink.tetrak.pages.dev

View logs

@stephen-masters
stephen-masters merged commit 965856f into main Nov 16, 2026
9 checks passed
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.

Normalise a low-contrast page before detection in the EasyOCR backends

1 participant