How to Define a Specific OCR Region of an Image

Often, you only need to extract text from a small part of an image, such as a total amount on an invoice or a specific field from a form. Scanning the full document is inefficient and can introduce errors by capturing irrelevant text.

IronOCR allows you to improve precision, performance, and accuracy by specifying the exact rectangular region to scan. This guide provides a step-by-step walkthrough on how to define a specific OCR region, extract text from it, and visually verify that your coordinates are correct for your OCR tasks.

Get Started with IronOCR

Start using IronOCR in your project today with a free trial.

First Step:
green arrow pointer


Perform OCR on Specific Region

To define a specific OCR region, you create a Rectangle object from the IronSoftware.Drawing namespace. This object requires four values: the x-coordinate, the y-coordinate, the width, and the height, all in pixels. The (x, y) coordinates represent the top-left corner of your desired area.

When you load your image using LoadImage, you pass this Rectangle as the second parameter. IronOCR will then restrict its OCR process to only the pixels within that bounding box.

TipsTo find the coordinates for your Rectangle, you can use a simple image editor like MS Paint. Open your input image, hover your mouse over the top-left and bottom-right corners of the specified region, and note the (x, y) pixel coordinates. You can then calculate the rectangle's properties: (x1, y1, width, height), where width = x2-x1 and height = y2-y1.

OCR Input

We'll use a sample image with three paragraphs. Our goal is to extract only the second paragraph and ignore the rest of the text.

OCR Input

Code

:path=/static-assets/ocr/content-code-examples/how-to/ocr-region-of-an-image.cs
using IronOcr;
using IronSoftware.Drawing;
using System;

var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();

// Define the specific region as a Rectangle
// (x, y) is the top-left corner.
var ContentArea = new Rectangle(x: 215, y: 1250, width: 1335, height: 280);

ocrInput.LoadImage("region-input.png", ContentArea);

var ocrResult = ocrTesseract.Read(ocrInput);

// Print the extracted text
Console.WriteLine(ocrResult.Text);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

As you can see from the console output, only the second paragraph is processed by the OCR.

OCR Output

Verifying the OCR region of an Image

To ensure you've selected the correct coordinates for the input image, you can visualize the ContentArea you defined. A simple way to do this is to draw the rectangle on the input image and save it as a new file with StampCropRectangleAndSaveAs. This helps you debug and fine-tune the coordinates for optimal performance.

Here is the output image after drawing the specified bounding box on our example input image from above.

Code

:path=/static-assets/ocr/content-code-examples/how-to/ocr-region-of-an-image-highlighted.cs
using IronOcr;
using IronSoftware.Drawing;

var ocrTesseract = new IronTesseract();
using var ocrInput = new OcrInput();

// Define the specific rectangular area to scan within the image.
// The coordinates are in pixels: (x, y) is the top-left corner of the rectangle.
var ContentArea = new Rectangle(x: 4, y: 59, width: 365, height: 26);

ocrInput.LoadImage("region-input.png", ContentArea);

var ocrResult = ocrTesseract.Read(ocrInput);

// Draws the rectangle from above in a blue bounding box on the image for visualization.
ocrInput.StampCropRectangleAndSaveAs(ContentArea, Color.Aqua, "region-input.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

OCR Highlighted Output

The light blue rectangle confirms that we have correctly isolated the second paragraph for processing.

Frequently Asked Questions

Why should I define a specific OCR region of an image?

Defining a specific OCR region of an image is useful for improving precision and accuracy by focusing on the area of interest, such as a total amount on an invoice, rather than scanning the entire document which can introduce errors.

How can I specify an OCR region using IronOCR?

You can specify an OCR region in IronOCR by creating a `Rectangle` object with the desired coordinates and dimensions. You then pass this rectangle to the `LoadImage` method, restricting OCR processing to that specific region.

What are the required parameters for defining an OCR region?

To define an OCR region, you need to provide four parameters for the `Rectangle` object: x-coordinate, y-coordinate, width, and height. These parameters determine the top-left corner and the size of the region.

How can I ensure the correct coordinates are selected for OCR?

To ensure the correct coordinates, visualize the defined ContentArea by drawing the rectangle on the input image using `StampCropRectangleAndSaveAs`. This helps in debugging and fine-tuning the coordinates.

What tools can I use to find the coordinates for my OCR region?

You can use a simple image editor like MS Paint to find the coordinates for your OCR region. Hover your mouse over the top-left and bottom-right corners of the desired area to note the (x, y) pixel coordinates.

What is the benefit of using IronOCR for region-specific OCR tasks?

IronOCR allows you to efficiently extract text from specific regions of an image, reducing errors and improving performance by preventing irrelevant text capture.

Can I visually verify the OCR region before processing?

Yes, you can visually verify the OCR region by drawing the rectangle on the input image. This confirms that the correct area is isolated for processing, ensuring accuracy.

What type of images can I process with IronOCR?

IronOCR can process a variety of image formats, allowing you to extract text from specific regions of images used in documents, forms, and invoices.

How does IronOCR handle the OCR process within a specified region?

IronOCR restricts its OCR process to pixels within the specified bounding box, ensuring that only the text within the defined region is extracted.

What is the output format of the OCR process in IronOCR?

The output format of the OCR process in IronOCR is accessible through the `OcrResult` property, allowing you to view and manipulate the extracted data as needed.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 5,041,124 | Version: 2025.11 just released