---
title: "OCR a 200 × 100 DPI fax in C#"
url: https://recursiveai.org/oneocr/cookbook/ocr-fax-with-non-square-pixels/
description: "Read a 200 × 100 DPI fax in C# with OneOcr. Correct for non-square pixels during OCR and get word boxes in the coordinates of the original TIFF."
version: "1.1.0"
---

# OCR a 200 × 100 DPI fax in C#

**OneOcr** is a free, open-source OCR library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneOcr) · [GitHub](https://github.com/recursive-ai-oss/oneocr-csharp) · [Docs](https://recursiveai.org/oneocr/docs/) · [Download example (.zip)](https://recursiveai.org/oneocr/cookbook/ocr-fax-with-non-square-pixels/ocr-fax-with-non-square-pixels.zip)

A fax can have different horizontal and vertical DPI. Pass both when reading `fax.tiff` from the zip.

```shell
dotnet add package RecursiveAI.OneOcr
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneImage;
using OneOcr;

var image = Image.Load("fax.tiff");
var engine = OcrEngine.LoadBundled();
var page = engine.Ocr(image,
    new() { Dpi = 200, VerticalDpi = 100 });
Console.WriteLine(page.Text);
var code = OcrDiagnosticCodes.PixelsStretched;
Console.WriteLine(page.Diagnostics.Any(
    d => d.Code == code));
```

Unzip [the example](https://recursiveai.org/oneocr/cookbook/ocr-fax-with-non-square-pixels/ocr-fax-with-non-square-pixels.zip), then `dotnet run`.

```text
Fax notice
True
```

`True` means OneOcr stretched the page internally for recognition. `RecursiveAI.OneOcr` brings in OneImage, which supplies `Image.Load`.

## The full program

The zip contains a synthetic, single-frame TIFF (480 × 120 pixels) labeled “Fax notice.” Here’s a PNG preview showing its stored pixels, without the stretch:

![The words Fax notice, vertically compressed in the stored raster](https://recursiveai.org/oneocr/images/ocr-fax-with-non-square-pixels/fax.png)

The program reads the same pixels twice, first as square pixels and then at the actual fax density.

```csharp
using OneImage;
using OneOcr;

var engine = OcrEngine.LoadBundled();
var image = Image.Load("fax.tiff");
var square = engine.Ocr(image, new OcrOptions { Dpi = 200 });
var fax = engine.Ocr(image, new OcrOptions { Dpi = 200, VerticalDpi = 100 });

foreach (var (label, page) in new[] { ("200 x 200 DPI", square), ("200 x 100 DPI", fax) })
{
    bool stretched = page.Diagnostics.Any(d => d.Code == OcrDiagnosticCodes.PixelsStretched);
    Console.WriteLine($"{label}: stretched = {stretched}");
}

Console.WriteLine($"Original image: {fax.Width} x {fax.Height} pixels");
foreach (var word in fax.Words)
{
    var box = word.Box;
    Console.WriteLine(FormattableString.Invariant(
        $"{word.Text}: ({box.Left:0.#}, {box.Top:0.#}) to ({box.Right:0.#}, {box.Bottom:0.#})"));
}
```

```text
200 x 200 DPI: stretched = False
200 x 100 DPI: stretched = True
Original image: 480 x 120 pixels
Fax: (46, 42) to (98, 55)
notice: (117, 41.5) to (217, 55)
```

If stretching would exceed the OCR pixel limit, OneOcr reads the page as-is and reports `PixelsNotStretched` instead.

## Variations

**Read the DPI from the TIFF header.** Use the file overload without a `Dpi` override when you trust the metadata. After loading `engine` as above:

```csharp
var page = engine.OcrPages("fax.tiff")[0];
Console.WriteLine(page.Diagnostics.Any(
    d => d.Code == OcrDiagnosticCodes.PixelsStretched));
```

```text
True
```

## Related recipes

- [Read character-level OCR boxes in C#](https://recursiveai.org/oneocr/cookbook/read-character-level-ocr-boxes/)
- [Extract text from an image in C#](https://recursiveai.org/oneocr/cookbook/extract-text-from-image/)

## The short answer

Set `OcrOptions.Dpi` to the horizontal resolution and `VerticalDpi` to the vertical resolution, then call `OcrEngine.Ocr` to get the page and its word boxes. Omitting `VerticalDpi` on the already-decoded image in this example tells the engine to use 200 DPI on both axes. To keep an overlay aligned with the unmodified image, use the returned boxes directly rather than stretching their coordinates again.

## What is the difference between horizontal and vertical DPI on a fax?

Horizontal DPI counts samples across a physical inch; vertical DPI counts samples down it. At 200 × 100 DPI, a 200-by-100-pixel region covers a square inch. A viewer that draws every pixel as a square shows that region twice as wide as it is tall. The effect is visible in the preview: the letters look shorter than on the page that was faxed.

For this sample OneOcr doubles the height internally, so it reads a 480 × 240 raster. It maps the boxes back before returning them; the `Fax` box ends at `y = 55` in the 120-row input, not at `y = 110` in the internal raster. Keep the original boxes if you draw on the original image. If you deliberately display the image at a different size, scale the boxes to match that display, just as you would with any OCR overlay.

## Does changing the DPI of a scanned image help OCR?

Changing the declared DPI does not add detail that the scanner missed. Giving OneOcr the *correct ratio* lets it compensate for distorted letter shapes, not recover lost strokes. Setting both axes to 300 DPI on this fax would discard the information that its pixels are rectangular. If the image has already been resampled to square pixels, don’t apply the original fax ratio again.

The `PixelsStretched` diagnostic (`OCR112`) tells you whether a correction actually ran. OneOcr leaves nearly square images alone and warns rather than stretching when the declared ratio is beyond 4:1 or the stretched raster would exceed the pixel limit. For those decisions, see [the stretch logic in OneOcr v1.1.0](https://github.com/recursive-ai-oss/oneocr-csharp/blob/9da32fbc91f5cda6f9f933bbefc3eb22183ffb3c/src/OneOcr/Layout/PageStretch.cs#L26-L73).
