How OCR works, and why it never tells you it guessed

A scan is a photograph of words. OCR is the bit that tries to turn it back into words.

When you scan a page, the computer does not get words. It gets a picture. Millions of dots, some dark, some light. To you it says “the respondent is not liable”. To the computer it is a pattern of dots, no different from a photo of your dog.

OCR (optical character recognition) is the software that looks at that picture and tries to find the letters in it. Roughly, it does five things.

  1. Cleans up the picture. Straightens a skew scan, removes specks, turns everything black and white so the letters stand out.
  2. Finds the text. Works out which parts of the page are writing, and which are stamps, lines or logos.
  3. Splits it up. Lines into words, words into letters.
  4. Guesses each letter. Compares each shape with shapes it has learnt. Modern OCR uses trained machine-learning models for this.
  5. Tidies up. Uses context and dictionaries to fix obvious errors. If it read “2room”, the “2” was probably a “Z”.
OCR in five steps: clean up, find the text, split it up, guess each letter, tidy up.
From dots to text. Step 4 is where the trouble lives.

What comes out is text that a computer, and Claude, can search and read. On a clean, typed page, modern OCR is very good.

The catch is step 4. Every letter is a guess, and OCR does not show its working. A watermark over “not” can come out as “now”. A name scrawled in the margin can vanish, because step 2 decided it was a stamp. The text that comes out looks just as sure of itself either way. There is no little red flag saying “I wasn’t sure about this bit”.

A watermark over the word not makes OCR read it as now.
Invented example. One letter, opposite meaning.

So the rule I work by: OCR makes a PDF readable. It does not make it reliable. Anything that matters (names, dates, amounts, and the word “not”) gets checked against the page itself. The longer version of this story, with my own near misses, is in The PDF is not your friend.

Sources: the five steps follow the standard descriptions of OCR, for example Educative and Alexander Thamm (the “2room” example). Diagrams are mine; the documents in them are made up.

Leave a comment

Leave a Reply

Discover more from ethics.bar

Subscribe now to keep reading and get access to the full archive.

Continue reading