# Image Preprocessing for OCR: Techniques and Document Examples

> Image preprocessing for OCR explained: when to resize, rotate, denoise or adjust contrast, a worked scan example, and how to check the document output.

Canonical: https://reducto.ai/guides/image-preprocessing-ocr

## The short answer

Image preprocessing is the set of operations applied to a page image before OCR: resizing, rotating or deskewing, converting to grayscale, removing noise and adjusting contrast. The goal is to give the recognizer clear, upright, consistently sized text. Use it to fix a specific, observed problem in your inputs, keep the original file, and judge each step by the document output it produces, not by how clean the image looks.

Not every manual step is required. In the example below, [Reducto Parse](https://reducto.ai/parse) returned the same structure from a noisy scan with and without cleanup. Classic engines such as Tesseract tend to depend on preprocessing more, which is why their documentation covers it in detail.

## Why input quality matters for OCR

OCR models learn what characters look like at a certain size, orientation and contrast. When an input falls outside that range, errors follow. Low resolution merges strokes. Rotation breaks line detection. Speckle noise from scanners or fax machines can be read as punctuation. Faint text and dark backgrounds blur the boundary between ink and paper.

These problems also travel downstream. A misread line can move a table cell, split a heading or change a total. That is why [OCR accuracy](https://reducto.ai/guides/most-accurate-ocr-software) should be measured on fields, tables and reading order, not just characters.

## Image preprocessing techniques for OCR

<Table html={"<table>\n  <thead>\n    <tr>\n      <th>Technique</th>\n      <th>Problem it addresses</th>\n      <th>Typical tools</th>\n      <th>Risk if overused</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>Resize or rescale</td>\n      <td>Text too small or too large for the recognizer</td>\n      <td>Interpolated upscaling; rescanning at a higher DPI</td>\n      <td>Upscaling cannot add detail that was never captured</td>\n    </tr>\n    <tr>\n      <td>Rotate and deskew</td>\n      <td>Pages scanned sideways or slightly tilted</td>\n      <td>Orientation detection, then a small-angle rotation</td>\n      <td>A wrong angle estimate tilts a straight page</td>\n    </tr>\n    <tr>\n      <td>Grayscale conversion</td>\n      <td>Color that carries no meaning</td>\n      <td>Single-channel conversion</td>\n      <td>Loses color-coded highlights, stamps and signatures</td>\n    </tr>\n    <tr>\n      <td>Denoise</td>\n      <td>Speckles, dust and fax artifacts</td>\n      <td>Median or Gaussian filters; morphological opening</td>\n      <td>Erases decimal points, accents and thin strokes</td>\n    </tr>\n    <tr>\n      <td>Contrast and binarization</td>\n      <td>Faint text, uneven lighting, shadows</td>\n      <td>Histogram equalization; global or adaptive thresholds</td>\n      <td>Drops light handwriting and fills in shaded cells</td>\n    </tr>\n    <tr>\n      <td>Crop and add borders</td>\n      <td>Scanner edges or text touching the image edge</td>\n      <td>Cropping, padding with white</td>\n      <td>Cuts off page numbers, footers or marginal notes</td>\n    </tr>\n  </tbody>\n</table>"} />

**Resize.** Tesseract's documentation says it [works best on images of at least 300 DPI](https://tesseract-ocr.github.io/tessdoc/ImproveQuality.html). If you control capture, rescanning at a higher resolution is better than upscaling afterwards.

**Rotate.** Fix 90- and 180-degree orientation first, then correct small skew. Orientation errors are common in photographed and batch-scanned pages, and they can break line detection entirely.

**Denoise.** A median filter replaces each pixel with the median of its neighbors, which removes isolated dots while keeping edges. Use the smallest kernel that works.

**Adjust contrast.** Grayscale plus a threshold turns a page into black text on white. Adaptive thresholds handle uneven lighting better than a single global value.

Common libraries for these operations include OpenCV, [Pillow](https://pillow.readthedocs.io/en/stable/reference/ImageFilter.html) and scikit-image.

## A small before-and-after example

This example uses a **synthetic** scan created for this guide: a delivery note with a title, a date line, a three-column table and a signature line. We added salt-and-pepper noise by setting 4% of pixels to black or white at random. The documented operation is a 3×3 median filter from Pillow 11.3.0, run on Python 3.12. The source image is never overwritten.

```python
from PIL import Image, ImageFilter

source = Image.open("source_scan.png")           # keep this file unchanged
cleaned = source.filter(ImageFilter.MedianFilter(size=3))
cleaned.save("cleaned_median3.png")              # write a separate copy

def dark_pixels(img, box):
    return sum(1 for v in img.crop(box).getdata() if v < 128)

margin = (0, 700, 1240, 820)                     # bottom strip with no text
print("source  dark pixels in blank margin:", dark_pixels(source, margin))
print("cleaned dark pixels in blank margin:", dark_pixels(cleaned, margin))
```

Output:

```text
source  dark pixels in blank margin: 2883
cleaned dark pixels in blank margin: 0
```

What changed: the filter removed every dark speck from the blank margin, and the page's total dark-pixel count fell from 58,456 to 39,608. Some of that drop is noise, and some is edge pixels from the text itself.

We then sent both files to Reducto Parse with the r-1 model. Both returned the same structure: a Title block, a Text block for the date and customer line, a Table block with the header row and all three item rows, and a Text block for "Received by: J. Rivera", each with `high` confidence. For this input, the median filter was not needed to get correct output. That is a useful result in itself: measure before you add a step to production.

## When preprocessing can remove useful evidence

Preprocessing changes the evidence. Strong denoising can delete decimal points, so 0.12 can be read as 012. Binarization can erase pencil notes, light stamps and checkbox marks. Grayscale removes the red ink that separates an approval from a draft. Cropping can drop a page number that links a page to its packet.

Keep the original image, record each operation and its parameters, and make sure reviewers can see the source page. Citations and bounding boxes only help if they point to an image a person can check.

## Evaluate downstream document output

Judge a preprocessing pipeline by what you extract:

1. Build a test set that separates clean scans, photos, faxes and handwriting.
2. Run OCR on the original and the processed version with the same settings.
3. Compare fields, table cells and reading order against labeled answers.
4. Track which documents got worse, not only the average.
5. Keep a step only if it helps on the inputs that need it.

The [OCR model comparison](https://reducto.ai/guides/best-ocr-models-accuracy-speed-cost) explains why a recognizer alone is not a full pipeline.

## Where Reducto fits

[Reducto Parse](https://reducto.ai/parse) accepts PDFs and images, including PNG, JPEG and TIFF, and returns layout-aware blocks such as titles, text and tables, each with a bounding box and a confidence value. With `return_ocr_data` enabled, it also returns word- and line-level OCR with a confidence score and detected rotation for each word, as described in the [Parse settings docs](https://docs.reducto.ai/configs/parse/settings). Use those signals to find pages that need attention instead of preprocessing every file. Try your own scans in [Reducto Studio](https://studio.reducto.ai/).

## Frequently asked questions

### What is image preprocessing for OCR?

It is cleanup applied to a page image before text recognition, such as resizing, rotation, denoising and contrast adjustment, to make characters easier to read.

### Does OCR always need preprocessing?

No. Clean scans often need none, and a layout-aware parser may handle moderate noise, as in the example above. Add steps when testing shows a specific input problem.

### Which preprocessing techniques help OCR most?

It depends on the defect. Rotation and deskew help tilted pages. Rescanning or resizing helps tiny text. Denoising helps speckled scans. Contrast adjustment helps faint text.

### Can preprocessing make OCR worse?

Yes. Aggressive filters and thresholds can erase punctuation, light handwriting and stamps. Always compare output against the original.
