IRONSOFTWAREHOME

How to Fix Image Colors for Reading in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Fix image colors in C# using IronOCR's binarization, grayscale, inversion, and color replacement methods to improve text readability and OCR accuracy. Read specific text colors for targeted extraction.

Quickstart: Isolate Specific Text Colors

Use IronOCR's SelectTextColor method to focus OCR on specific text colors - no complex image manipulation required. Load an image, choose the text color and tolerance, and extract only that text for accurate OCR results.

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2Copy and run this code snippet.

    new IronTesseract().Read(new IronOcr.OcrImageInput("sample.jpg").SelectTextColor(new IronSoftware.Drawing.Color("#DB645C"), 60));
    C#
  3. 3Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer

How Do I Binarize an Image to Improve OCR?

Binarization converts images to two-color format, typically black and white. This separates text from background and reduces noise, making text more distinct and easier to read.

Why Does Binarization Improve OCR Accuracy?

Apply binarization using the Binarize method. OCR works best with high-contrast images featuring black text on white backgrounds. This method creates clear distinction between background and characters.

Binarization excels with scanned documents having uneven lighting or background noise. The algorithm analyzes images and determines optimal thresholds to separate foreground text from background. For advanced preprocessing techniques, see the OCR Image Optimization Filters guide.

What Is the Code Implementation for Binarization?

using IronOcr;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply binarize affect
imageInput.Binarize();

// Export the modified image
imageInput.SaveAsImages("binarize.jpg");

For batch processing, combine binarization with other filters. Use the Filter Wizard to determine the best filter combination for your images.

How Can I Export and Compare Results?

Export modified images using the SaveAsImages method. Compare images before and after binarization below.

Sample image with red and black text on blue-gray background showing OCR challenges before binarization
Binarized version showing clear black text on pure white background for optimal OCR processing

How Do I Convert Images to Grayscale for Better Reading?

Converting images to grayscale reduces visual clutter and improves readability. This helps when original colors distract from content.

When Should I Use Grayscale Over Other Methods?

Apply grayscale using the ToGrayScale method. The process averages R, G, and B values.

Grayscale works well with colored backgrounds or watermarks that interfere with text recognition. Unlike binarization, grayscale preserves detail in images with subtle variations. Use it for photographs with embedded text or complex layouts. For low-quality scans, see Fixing Low Quality Scans & Images.

What Is the Simple Code for Grayscale Conversion?

// Apply grayscale affect
imageInput.ToGrayScale();

For varied image qualities, combine grayscale with other preprocessing steps. The OcrInput Class documentation explains chaining multiple filters.

How Does Grayscale Compare to the Original?

Sample text with red headers and black body text showing multiple colors before grayscale conversion
Grayscale document with clear text about tech executives, demonstrating improved readability after conversion

When Should I Invert Image Colors?

Inverting colors enhances contrast. Converting white text on black backgrounds to black text on white backgrounds improves readability.

How Do I Implement Color Inversion?

Use the Invert method to invert colors. Pass a boolean value to remove color channels and return grayscale.

Color inversion handles negative images or dark-themed screenshots. Modern applications use dark mode interfaces that challenge traditional OCR. Inverting these images ensures optimal recognition. For various image types, see the Fast OCR Configuration guide.

// Apply invert affect
imageInput.Invert();

For batch processing with mixed document types, implement automatic dark background detection. Computer Vision features in IronOCR identify when inversion is needed.

What Is the Difference Between Inversion Options?

Compare the Invert method with and without grayscale:

Color-inverted document maintaining original color channels with reversed values
Business text with inverted colors showing white text on dark background demonstrating color inversion effect

How Can I Replace Specific Colors in an Image?

Replace specific colors to highlight or de-emphasize elements. Use this to improve text prominence or correct problematic contrasts.

Why Is Tolerance Important in Color Replacement?

The ReplaceColor method requires the current color, new color, and tolerance value. Higher tolerance handles blurry images better.

Tolerance determines how closely pixels must match your target color. Low values (0-50) suit uniform colors. Higher values (100-200) handle anti-aliased text or compression artifacts. This helps with scanned documents where ink bleeding or paper texture creates variations.

How Do I Implement Color Replacement?

using IronOcr;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sample.jpg");
IronSoftware.Drawing.Color currentColor = new IronSoftware.Drawing.Color("#DB645C");
IronSoftware.Drawing.Color newColor = IronSoftware.Drawing.Color.DarkCyan;

// Replace color
imageInput.ReplaceColor(currentColor, newColor, 80);

// Export the modified image
imageInput.SaveAsImages("replaceColor");

How Do I Handle Advanced Color Replacement Scenarios?

Chain multiple replacements for complex scenarios:

/* :path=/static-assets/ocr/content-code-examples/how-to/image-color-correction-multiple-replacements.cs */
// Replace multiple colors in sequence
using var imageInput = new OcrImageInput("multi-color-document.jpg");

// Replace red text with black
imageInput.ReplaceColor(IronSoftware.Drawing.Color.Red, IronSoftware.Drawing.Color.Black, 70);

// Replace blue headers with dark gray
imageInput.ReplaceColor(IronSoftware.Drawing.Color.Blue, IronSoftware.Drawing.Color.DarkGray, 60);

// Replace light yellow background with white
imageInput.ReplaceColor(new IronSoftware.Drawing.Color("#FFFACD"), IronSoftware.Drawing.Color.White, 40);

// Perform OCR on the cleaned image
var result = ocrTesseract.Read(imageInput);

For complex color replacements, see Image Correction Filters for additional preprocessing techniques.

What Are the Visual Results of Color Replacement?

Text sample with orange-red colored names and content on blue background showing original colors before replacement
Document after color replacement showing dark cyan headers replacing original orange-red text

How Do I Read Only Specific Text Colors?

Read specific text colors using the SelectTextColor method. Specify the target color and tolerance (0-255). Tolerance represents allowable differences between pixel and selected color for R, G, and B values.

How Does Color Tolerance Affect Results?

using IronOcr;
using System;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Text color to focus on
IronSoftware.Drawing.Color focusColor = new IronSoftware.Drawing.Color("#DB645C");

// Specify which text color to read
imageInput.SelectTextColor(focusColor, 60);

// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Output result to console
Console.WriteLine(ocrResult.Text);

Use selective color reading for forms with color-coded sections, extracting highlighted text, or reading specific warning messages. For structured data extraction, see OcrResult Class for advanced processing.

What Output Can I Expect from Color Selection?

The OCR result reads only orange-colored text:

Debug console showing OCR extracted orange text: MASAYOSHI SON and YASUMITSU SHIGETA from business document

How Do I Save Modified PDFs with Applied Filters?

IronOCR saves modified PDFs with or without filters. The SaveAsSearchablePdf method's second parameter specifies whether to save with filters applied.

What Is the Implementation for Searchable PDFs?

using IronOcr;

// Create OCR engine: filters are applied at the OcrInput level, so no configuration changes are needed here
var ocr = new IronTesseract();
var ocrInput = new OcrInput();

// Load the scanned PDF as the OCR source
ocrInput.LoadPdf("invoice.pdf");

// Convert to grayscale: removes color noise that can reduce OCR accuracy on color-printed documents
ocrInput.ToGrayScale();
// Run OCR on the preprocessed input
OcrResult result = ocr.Read(ocrInput);

// Write the searchable PDF; true = embed the grayscale-filtered image rather than the original color scan
result.SaveAsSearchablePdf("outputGrayscale.pdf", true);

When Should I Apply Filters to the Saved PDF?

Apply filters when creating cleaner, more readable documents. This helps with archival purposes or sharing documents across different devices. See Create Searchable PDFs by OCR for more information.

For complex documents with tables, explore Read Table in Document for specialized extraction. For high-volume processing, see Multithreaded Tesseract OCR to optimize filter application across multiple documents.

Frequently Asked Questions

What is the purpose of image binarization in C# OCR?

Binarization converts images to a two-color format, typically black and white, to separate text from the background and reduce noise. This enhances text readability and OCR accuracy by creating high-contrast images.

How does the SelectTextColor method improve OCR results?

The SelectTextColor method allows you to focus OCR on specific text colors, enabling targeted text extraction without complex image manipulation. This improves accuracy when dealing with documents containing multiple text colors.

When should I use grayscale conversion in image preprocessing?

Grayscale conversion is useful for reducing visual clutter in images with distracting colors. It works well with colored backgrounds or watermarks that interfere with text recognition, preserving detail in complex layouts.

Why is color inversion beneficial for OCR?

Color inversion enhances contrast by converting white text on black backgrounds to black text on white backgrounds, thus improving readability. It is particularly helpful for dark-themed screenshots or negative images.

What role does tolerance play in the ReplaceColor method?

Tolerance in the ReplaceColor method defines how closely pixels must match the target color for replacement. It is crucial for handling blurry images or documents with ink bleeding, improving text prominence and contrast.

How can IronOCR improve OCR processing speed?

IronOCR supports multithreaded processing, allowing for faster OCR when handling high-volume documents. This speeds up the application of filters across multiple images, enhancing overall efficiency.

What outputs are expected from selective color reading with OCR?

The OCR result from selective color reading focuses only on specified colors, such as extracting highlighted texts or specific warning messages, enabling precise data extraction from color-coded documents.

How can I create searchable PDFs with IronOCR?

IronOCR allows you to save modified PDFs using the SaveAsSearchablePdf method. Filters like grayscale can be applied to improve text readability and noise reduction in the resulting documents.

What preprocessing steps can enhance OCR accuracy for low-quality scans?

For low-quality scans, preprocessing steps like binarization, grayscale conversion, and color inversion can significantly improve text readability and OCR accuracy by reducing noise and enhancing contrast.

How can IronOCR help with structured data extraction?

IronOCR provides advanced processing capabilities like the OcrResult Class, which supports structured data extraction from images, making it ideal for forms with color-coded sections and highlighted text.

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 6,236,385Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

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