A scan with coloured paper, a grey background, or faint print confuses OCR because the engine must first decide which pixels are ink. Converting the image to grayscale and applying a threshold turns it into clean black text on white, which is the input OCR engines handle best.
What you need
- OCRmyPDF installed
- A noisy scan, such as a photocopy on coloured paper
- A transcript of a few lines of the page to compare against
Step 1: Run OCR without preprocessing
Run OCRmyPDF on the scan with default settings and count the wrong words on one test page.
Step 2: Run OCR with thresholding
Run ocrmypdf –threshold input.pdf output.pdf to apply thresholding, then count the wrong words on the same test page. The –threshold option is experimental and may need a retry with a different method.
Step 3: Compare the error counts
If thresholding cut the errors, use it for the whole document; if it made things worse, try the clean or deskew options instead.
Worked example: synthetic preprocessing comparison on a faded photocopy
The table below is a synthetic example. It shows the expected result of comparing preprocessing runs; no OCR was run.
| Run | Words checked | Wrong words |
|---|---|---|
| Default | 180 | 14 |
| Threshold | 180 | 5 |
| Grayscale only | 180 | 9 |
| Threshold + deskew | 180 | 4 |
Expected result (UNTESTED). the default run makes 14 errors in 180 words, thresholding cuts that to 5, and thresholding plus deskew cuts it to 4. Use thresholding with deskew for this document. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Thresholding is experimental in OCRmyPDF and can make a clean scan worse, so always test on one page first.
- The best threshold method depends on the scan; a method that helps one document can hurt another.
- Preprocessing cannot recover text that is physically missing from the scan.
