IRONSOFTWAREHOME
OCR Image Color Editing
using IronOcr;
using IronSoftware.Drawing;
using System;

var ocrTesseract = new IronTesseract();

using var ocrInput = new OcrInput();
ocrInput.LoadImage("blue_and_pink.png");

ocrInput.WithTitle("Recolored");

ocrInput.ReplaceColor(Color.Pink, Color.White, 10);
// Pink detection has 10% tolerance

ocrInput.ReplaceColor(Color.Blue, Color.Black, 5);
// Blue detection has 5% tolerance

// Export the modified image so you can manually inspect it.
foreach (var page in ocrInput.GetPages())
{
    page.SaveAsImage($"black_and_white_page_{page.Index}.bmp");
}

var ocrResult = ocrTesseract.Read(ocrInput);
Console.WriteLine(ocrResult.Text);
Imports IronOcr
Imports IronSoftware.Drawing
Imports System

Dim ocrTesseract = New IronTesseract()

Using ocrInput = New OcrInput()
    ocrInput.LoadImage("blue_and_pink.png")

    ocrInput.WithTitle("Recolored")

    ocrInput.ReplaceColor(Color.Pink, Color.White, 10)
    ' Pink detection has 10% tolerance

    ocrInput.ReplaceColor(Color.Blue, Color.Black, 5)
    ' Blue detection has 5% tolerance

    ' Export the modified image so you can manually inspect it.
    For Each page In ocrInput.GetPages()
        page.SaveAsImage($"black_and_white_page_{page.Index}.bmp")
    Next

    Dim ocrResult = ocrTesseract.Read(ocrInput)
    Console.WriteLine(ocrResult.Text)
End Using
NuGet Download
PM > Install-Package IronOcr
OCR Image Color Editing

OCR Image Color Editing

OCR works faster and more accurately when we read black text on a white background.

If we have, for example, blue text on a pink background, we will want to swap blue to black and pink to white before performing OCR.

This can be very time-consuming and slow using System.Drawing, but it is completely automated with IronOCR.

The OcrInput.ReplaceColor method allows us to replace one color with another in a document. This method is adaptive, allowing you to specify a percentage tolerance for a match to an exact RGB color. This removes the need to use Photoshop or ImageMagick scripts to prepare images for OCR.

ReplaceColor Method Parameters

  • The first parameter is the color to be replaced.
  • The second parameter is the replacement color.
  • The third optional parameter specifies tolerance for how closely the colors must match, which allows for variations within the specified percentage.
Learn More About Image Color Correction in OCR
View on GitHub

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required