Image preprocessing
Deskewing · Binarization
Cleaning a page image before OCR: rotating it upright, straightening skew, removing noise and converting to black and white so characters separate from the background.
In DocSlurpGlossary entry
On this page
Image preprocessing cleans a page image so that OCR can separate characters from everything else. The classic steps are:
- Orientation: rotate a page scanned sideways or upside down by 90, 180 or 270 degrees.
- Deskewing: straighten a page fed in at a slight angle, so text lines run horizontally.
- Binarization: turn grayscale into pure black and white. Otsu’s method picks the threshold automatically, from the histogram of gray levels; adaptive methods pick a different threshold per region, which helps with shadows from phone photos.
- Denoising: remove specks, scanner dust and JPEG artifacts that OCR might read as punctuation.
- Scaling: enlarge small text so letters have enough pixels. See DPI.
Each step can turn an unreadable scan into a clean one. site-inspection.jpg, taken at an angle in poor light, may need all five.
The gotcha: every step is a bet, and a wrong bet is worse than no bet. Binarization with the wrong threshold erases light pencil marks or thin strokes. Deskewing a page that has an intentionally rotated table rotates everything else. And an orientation detector that is right 99% of the time still turns one upright page in a hundred upside down, which destroys that page completely. Good pipelines act only on strong evidence, measure the false-positive rate on upright pages, and leave ambiguous pages alone.
Modern vision-language models are trained on messy images and need less of this, but rotation still hurts them.
In DocSlurp
In DocSlurp
An orientation detector exists but is marked eval-only and is not wired into production; its header records that a wrong rotation is worse than none (core/worker/src/routing/orientation.ts). Rasters are size-bounded before rendering (core/worker/src/lib/raster-bounds.ts). Other cleanup is left to the OCR engine and vision models.