How to Read Photos Using IronOCR

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 tutorial, we'll briefly provide an input and an example on how to use ReadPhoto and how to manipulate the results object. We'll also discuss scenarios where developers might prefer 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 an OcrInput then 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 converted 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].PageNumber;

// 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).PageNumber

' 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)
$vbLabelText   $csharpLabel

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 "TextRegions" property 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 the ReadPhoto method compared to the standard Read is the result object and the file format it takes. LoadImageFrame specifically only takes in tiff and gif and does not support formats like jpeg for several reasons.

Comparison between TIFF and JPEG Images

TIFF as a file format is lossless and usually used to condense multiple pages and multiple frames 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 JPEG formats and as such requires a different method to fully extract text from it.

Furthermore, TIFF images use a different compression method, so IronOCR has to use a specialized method to decipher the text.

Here's a further breakdown between TIFF and JPEG for comparison.

FeatureTIFF (Tagged Image File Format)JPG/JPEG (Joint Photographic Experts Group)
CompressionLossless or uncompressed (preserves quality)Lossy compression (reduces quality for smaller file size)
File SizeLarge (due to high quality and optional lack of compression)Smaller, optimized for web use and fast loading
Image QualityHigh (ideal for professional use, retains all details)Lower (due to lossy compression, some quality is sacrificed)
Color DepthSupports high color depth (up to 16-bit or 32-bit per channel)24-bit color (16.7 million colors)
Use CaseProfessional photography, publishing, scanning, archivingWeb images, social media, everyday photos
TransparencySupports transparency and alpha channelsDoes not support transparency
EditingGood for multiple edits (no quality loss with resaving)Quality degrades with repeated edits and saves
CompatibilityWidely supported in professional softwareUniversally supported across all platforms and devices
AnimationDoes not support animationDoes not support animation
MetadataStores extensive metadata (EXIF, layers, etc.)Stores EXIF metadata but is more limited

Different scenarios

Developers will have to consider each use case in production to further optimize and allow their applications to run effectively. Although ReadPhoto is suited for complex images such as TIFF like above, the result would be processed slowly. On the other hand, JPEG may be lower in quality but the operation would generally be faster. However, 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 of 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.

Frequently Asked Questions

What is the ReadPhoto method in C#?

The ReadPhoto method in IronOCR for C# is designed to extract text from complex image formats like TIFF and GIF, converting them into searchable digital data using Optical Character Recognition (OCR).

Why should I use ReadPhoto instead of the standard Read function?

ReadPhoto is optimized for handling complex image formats like TIFF and GIF, which require special processing due to their compression and quality characteristics, making it more suitable for these types of images compared to the standard Read function.

How can I ensure optimal text extraction using OCR in C#?

To ensure optimal text extraction with OCR in C#, consider the image quality and format. Using IronOCR's ReadPhoto method for high-quality and complex formats like TIFF can enhance accuracy and efficiency.

What image formats does the ReadPhoto method support?

The ReadPhoto method in IronOCR supports complex image formats such as TIFF and GIF, which are ideal for high-quality text extraction tasks.

What are the benefits of converting TIFF files using OCR?

Converting TIFF files using OCR with IronOCR's ReadPhoto method allows for the transformation of high-quality images into searchable and editable digital data, which is beneficial for document management and archiving.

How does OCR technology enhance document processing?

OCR technology automates the conversion of text from images to digital data, significantly increasing processing speed and accuracy, especially in managing large document volumes.

What factors influence the choice of image processing methods in OCR?

Factors influencing the choice include image format and quality, processing speed, and specific use case requirements. IronOCR's ReadPhoto is ideal for high-quality, complex images, while other methods might be more efficient for simpler formats.

Can IronOCR's ReadPhoto method be used for color images?

Yes, IronOCR's ReadPhoto method can process color images, particularly in formats like TIFF and GIF, allowing for accurate text extraction in full-color documents.

What role does the 'confidence' property play in OCR results?

The 'confidence' property in OCR results provides a statistical measure of the accuracy of the text extraction, helping developers assess the reliability of the digitized data.

How can developers use OCR results from ReadPhoto in their applications?

Developers can use the OCR results from IronOCR's ReadPhoto by accessing the OcrPhotoResult property, which includes extracted text, confidence scores, and text regions, enabling further data processing and application integration.

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