Updated February 16, 2025
Share:

How to Read Photos Using IronOCR

by Curtis Chau

When dealing with large volumes of documents, particularly scanned images like TIFF files, manually extracting text can be time-consuming and prone to human error. This is where Optical Character Recognition (OCR) comes in, offering an automated method to accurately convert text from images into digital data. OCR technology can handle the complexity of images, such as scanned documents or photographs, and turn them into searchable, editable text. This not only speeds up document processing but also ensures more accurate data extraction compared to manual transcription.

Using OCR on formats like TIFF, which may be hard to read due to their size, color depth, or compression, enables businesses and developers to quickly digitize and manage vast amounts of data. With OCR solutions like IronOCR's ReadPhoto function, developers can extract text from images and even perform advanced operations such as searching for keywords or converting scanned data into searchable PDFs. This technology is especially useful for industries that deal with legal documents, archives, or receipts, where efficient data retrieval is critical.

In this tutroial, we'll briefly provide an input and an example on how to use ReadPhoto and how to mainpulate the results object. As well as sceanrions where developers would find them using ReadPhoto instead of the standard Read from IronOCR.

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

First Step:
green arrow pointer

To use this function, you must also install the IronOcr.Extension.AdvancedScan package.

Read Photos Example

Reading high quality photo formats such as tiff and gif is relatively simple using IronOCR. First we create a new variable and assign it as a OcrInput then we load the image in using LoadImageFrame. Finally we use the ReadPhoto method and obtain the results.

Please note

  • Since Tiff contains multiple frames within a singular image, the frameNumber parameter is needed. Furthermore the index starts at 0, rather than 1.
  • The method currently only works for English, Chinese, Japanese, Korean, and LatinAlphabet.
  • Using advanced scan on .NET Framework requires the project to run on x64 architecture.

Input

Since most browsers do not natively support the TIFF format, you can download the TIFF input here. To display the TIFF file, I will convert it to WEBP.

Input

Code

:path=/static-assets/ocr/content-code-examples/how-to/read-photo-read-photo.cs
using IronOcr;
using IronSoftware.Drawing;
using System;

// Instantiate OCR engine
var ocr = new IronTesseract();

using var inputPhoto = new OcrInput();
inputPhoto.LoadImageFrame("ocr.tiff", 0);

// Read photo
OcrPhotoResult result = ocr.ReadPhoto(inputPhoto);

// Index number refer to region order in the page
int number = result.TextRegions[0].FrameNumber;

// Extract the text in the first region
string textinregion = result.TextRegions[0].TextInRegion;

//Extract the co_ordinates of the first text region
Rectangle region = result.TextRegions[0].Region;

var output = $"Text in First Region: {textinregion}\n"
             + $"Text Region:\n"
             + $"Starting X: {region.X}\n"
             + $"Starting Y: {region.Y}\n"
             + $"Region Width: {region.Width}\n"
             + $"Region Height: {region.Height}\n"
             + $"Result Confidence: {result.Confidence}\n\n"
             + $"Full Scnned Photo Text: {result.Text}";

Console.WriteLine(output);
Imports Microsoft.VisualBasic
Imports IronOcr
Imports IronSoftware.Drawing
Imports System

' Instantiate OCR engine
Private ocr = New IronTesseract()

Private inputPhoto = New OcrInput()
inputPhoto.LoadImageFrame("ocr.tiff", 0)

' Read photo
Dim result As OcrPhotoResult = ocr.ReadPhoto(inputPhoto)

' Index number refer to region order in the page
Dim number As Integer = result.TextRegions(0).FrameNumber

' Extract the text in the first region
Dim textinregion As String = result.TextRegions(0).TextInRegion

'Extract the co_ordinates of the first text region
Dim region As Rectangle = result.TextRegions(0).Region

Dim output = $"Text in First Region: {textinregion}" & vbLf & $"Text Region:" & vbLf & $"Starting X: {region.X}" & vbLf & $"Starting Y: {region.Y}" & vbLf & $"Region Width: {region.Width}" & vbLf & $"Region Height: {region.Height}" & vbLf & $"Result Confidence: {result.Confidence}" & vbLf & vbLf & $"Full Scnned Photo Text: {result.Text}"

Console.WriteLine(output)
VB   C#

Output

output

Text: The extracted Text from OCR Input.

Confidence: A "double" property that indicates the statistical accuracy confidence of an average of every character, with one being the highest and 0 being the lowest.

TextRegions: A list of the property "TextRegions" indicating where the OCR text and its location is within the input. In the example above, we printed the frame number as well as the rectangle containing the text.


Difference between ReadPhoto and Read

The main difference between this readPhoto method compared to the standard read is the result object and file format it takes. LoadImageFrame specfically only takes in tiff and gif and doesn't take formats like Jpeg and there are a few reasons of that.

Comparison btetween Tiff and Jpg Images

Tiff as a file format is loselss and usually used to condense multiple pages and mulit frame into one single format. It is typically used for high quality, multi-image storage( for example legal documents, medical images). It is much more complex than standard jpg formats and as such requires a different way to full extract text form it.

Furthermore Tiff images only uses a different compression as such IronOCR has to use a specailized method to decipher the text.

Here's a further breakdown between tiff and jpg as a comparsion.

Feature TIFF (Tagged Image File Format) JPG/JPEG (Joint Photographic Experts Group)
Compression Lossless or uncompressed (preserves quality) Lossy compression (reduces quality for smaller file size)
File Size Large (due to high quality and optional lack of compression) Smaller, optimized for web use and fast loading
Image Quality High (ideal for professional use, retains all details) Lower (due to lossy compression, some quality is sacrificed)
Color Depth Supports high color depth (up to 16-bit or 32-bit per channel) 24-bit color (16.7 million colors)
Use Case Professional photography, publishing, scanning, archiving Web images, social media, everyday photos
Transparency Supports transparency and alpha channels Does not support transparency
Editing Good for multiple edits (no quality loss with resaving) Quality degrades with repeated edits and saves
Compatibility Widely supported in professional software Universally supported across all platforms and devices
Animation Does not support animation Does not support animation
Metadata Stores extensive metadata (EXIF, layers, etc.) Stores EXIF metadata but is more limited

Different scenarios

Developers will have to consider each use case on the production to further optimize and allow their applications to run effictively. Although readPhoto is suited for complex images such as Tiff like above, the result would be processed slowly. On the other hand, jpg may be lower in quality but the operation would generally be faster. However the image quality such as having noise would result in a low confidence rate with the OCR.

Using the confidence property in the OcrPhotoResults or any class that uses the interface IOcrResult would give you an idea on how accurate the results are, allowing developers to test, re-iterate and optimize as desired.

Developers should find a fine line between efficiency and accuracy ensuring that the images are up to a certain threshold for consistency.