Image Classification
ONNX
onnxruntime
document-orientation
deskew
ocr
image-preprocessing
cpu
foliokestrel's picture
Add a local searchable-PDF orientation reader, a stale OCR example, and verified results on 343 USGS and 553 Bengali archive pages
88248d0 verified
|
Raw History Blame Contribute Delete
7.32 kB
# Reading direction in four complete USGS reports
A PDF's searchable layer can identify landscape plates that take effort to find by paging through a bound volume. Across these four reports, the text-layer rule suggested a 90° clockwise turn on 13 pages. A blinded visual review agreed on all 13. Eight were figures, four were photographs, and one was a table. A rotated plate may reflect the publisher's intended binding. The study measures how a reader would orient the main content.
## Automatic decisions on the original PDFs
| Method | Upright pages kept / 310 | Sideways pages corrected / 13 | Known pages referred | Blank pages referred / 20 | Wrong decisions on known pages |
|---|---:|---:|---:|---:|---:|
| Leave every page as displayed | 310 | 0 | 0 | 0 | 13 |
| Tesseract OSD, confidence ≥15 | 119 | 0 | 204 | 20 | 0 |
| Embedded text, ≥24 votes and ≥80% agreement | 310 | 13 | 0 | 20 | 0 |
The text layer gave decisions on 323/343 pages. It agreed with OSD on all 119 where both made a decision. OSD referred every sideways plate, including the table on physical page 26 of Water-Supply Paper 1. Its raw angle for that table was correct at confidence 2.56. The text layer had 759 agreeing glyphs. All four sideways photographs had between 59 and 74 agreeing glyphs.
On one CPU job, glyph voting took 4.11 seconds in total, thumbnail scoring took 12.68 seconds, and OSD took 138.23 seconds plus 22.62 seconds of page rendering. Timings cover the measured loops, with already downloaded PDFs, and depend on the machine and document. [Timings by book](timings.json)
## Manually inspecting thumbnail candidates
Each column gives the number of known turns found by reviewing the K highest-ranked physical pages in each book. The random baseline draws K pages uniformly without replacement within the same book.
| Water-Supply Paper | PDF pages | Known turns | First 5 | First 10 | First 20 | Expected random hits at 5 / 10 / 20 | Excluded pages / turns among them |
|---|---:|---:|---:|---:|---:|---|---|
| 1 | 62 | 9 | 5 | 9 | 9 | 0.73 / 1.45 / 2.90 | 1 / 0 |
| 8 | 69 | 4 | 3 | 4 | 4 | 0.29 / 0.58 / 1.16 | 11 / 0 |
| 36 | 98 | 0 | 0 | 0 | 0 | 0 / 0 / 0 | 2 / 0 |
| 67 | 114 | 0 | 0 | 0 | 0 | 0 / 0 / 0 | 11 / 0 |
Across books, five inspections each found 8/13 turns in 20 inspections (40% precision, 62% recall). Ten each found 13/13 in 40 (32.5% precision, 100% recall), versus 2.03 expected at random. Twenty each found 13/13 in 80 (16.25% precision). Inspecting all 25 filtered pages added 20 blank leaves and five upright photographs. Per-book recall is undefined for the two reports containing zero known turns. Every ranked positive and every exclusion has a physical page number and a reason or rank. [Per-book results](results.json) · [All 343 page records](pages.jsonl)
## Sampling and judgments
The protocol fixed the sampling order, document size limits, ranking and review budgets before viewing the pages. The first four eligible reports in the hash order all met the criteria. One AI reviewer judged every page under a shuffled ID after an independent quarter-turn. The reviewer used the dominant body, caption or natural up of a photograph. The label checksum was recorded before revealing source identity, injected angle or method output. This gives a single reading of each plate. Thirteen turns in two books provide limited evidence about other collections, reading systems or half-turns. [Protocol](PROTOCOL.md) · [Original judgments](labels.tsv) · [Source key](key.jsonl) · [Joined reference](reference.jsonl)
Source PDFs and bibliographic records are provided by the U.S. Geological Survey, Publications Warehouse. Physical page numbers include covers and blank leaves. Download URLs, file sizes and SHA-256 digests identify the exact revisions used here. [Source manifest](sources.jsonl)
- *Pumping water for irrigation* (1896). [Water-Supply Paper 1](https://pubs.usgs.gov/publication/wsp1)
- *Windmills for irrigation* (1897). [Water-Supply Paper 8](https://pubs.usgs.gov/publication/wsp8)
- *Operations at river stations, 1899, Part II* (1900). [Water-Supply Paper 36](https://pubs.usgs.gov/publication/wsp36)
- *The motions of underground waters* (1902). [Water-Supply Paper 67](https://pubs.usgs.gov/publication/wsp67)
## Coverage in a second archive
A follow-up applied the identical text rule to existing blinded judgments from 16 historical Bengali books. The panel included four pages per book chosen using thumbnail geometry and a random comparator. One selected geometry volume had already been reviewed in full after a sideways table was found. Its 493 pages and the 64-page panel overlap on four physical pages.
None of the 553 distinct pages supplied a usable glyph vote. The text rule referred all 543 upright pages, five known turns, and five unclear pages. The absence of directional text evidence can be detected before paying the cost of image OCR. These selected pages measure coverage in those editions. [Per-page outputs](other-archive/pages.jsonl) · [Source URLs, attribution and Wikimedia revision digests](other-archive/sources.jsonl) · [Judgments](other-archive/reference.jsonl)
## Reproduce
Run these commands from the `text-layer` directory using Python 3.10+. The first command below verifies the saved decisions using only Python's standard library. The full replay requires network access to the four USGS files (about 51 MiB in total) and Tesseract's orientation data.
```sh
python study/verify.py study
python -m pip install pypdfium2==5.15.2 pypdf==7.2.0 tesserocr==2.9.2 numpy Pillow
python study/check_text_angle.py
python study/fetch_pdfs.py pdfs
mkdir -p tessdata
curl -fL https://raw.githubusercontent.com/tesseract-ocr/tessdata_fast/87416418657359cb625c412a48b6e1d6d41c29bd/osd.traineddata -o tessdata/osd.traineddata
python study/check_cli.py pdfs
OMP_THREAD_LIMIT=1 python study/evaluate.py pdfs tessdata replay
python study/verify.py replay
```
A second run downloaded the four sources again and reproduced both the per-page outputs and aggregate scores byte for byte. Compare `replay/pages.jsonl` and `replay/results.json` to the included files. Numeric outputs can depend on PDFium, Tesseract and the system build. The 38-case fixture tests visible and hidden text, all combinations of page and glyph quarter-turns, sparse votes, competing directions and off-axis text. The command-line check exercises the deliberately stale hidden layer in the five-page example and compares the reader's CSV to all 343 saved decisions.
For the second archive, save the source files listed in `study/other-archive/sources.jsonl` as `BOOK_ID.pdf` in a directory named `dli-pdfs`, using each record's numeric `pageid` as the book ID. Run `python study/other-archive/evaluate_transfer.py dli-pdfs transfer-replay`. It checks the stored SHA-1 revision and file size before evaluating each book.
The `shown_cw` field describes the correction judged on the rotated card, and `native_cw` is the additional turn needed in the original PDF view. A null native angle denotes an uncertain or mixed judgment. Per-method records retain the raw proposal and score even when referred. The scanner's rank is one-based within the book; a null rank accompanies an exclusion reason. [Blinding code](prepare.py) · [Scoring code](evaluate.py)