C# Image Correction Filters for Improved OCR Reading
IronOCR provides five essential image correction filters (sharpen, enhance resolution, denoise, dilate, and erode) that preprocess images to significantly improve OCR accuracy by enhancing text clarity and reducing noise before text extraction.
Quickstart: Apply Sharpen Filter for Clear Text
Use IronOCR's OcrImageInput to sharpen a blurry image with a single line of code. This example demonstrates image enhancement for accurate OCR.
-
Install IronOCR with NuGet Package Manager
PM > Install-Package IronOcr -
Copy and run this code snippet.
new IronOcr.OcrImageInput("sample.png").Sharpen().SaveAsImages("output.png"); -
Deploy to test on your live environment
Start using IronOCR in your project today with a free trial
Minimal Workflow (5 steps)
- Download a C# library for image correction using filters
- Import the PDF document and images for reading
- Apply desired filters, such as sharpening, enhancing resolution, denoising, dilation, and erosion
- Export the corrected image for viewing
- Use the
Readmethod for OCR processing
How Do I Apply the Sharpen Filter?
This filter increases contrast along edges in the image, creating more defined text boundaries. It improves text clarity, making character recognition more accurate.
Why Does Sharpening Improve OCR Accuracy?
The sharpen filter emphasizes boundaries between text and background by enhancing edge contrast. Character recognition algorithms need clear, distinct letter shapes to function properly. Blurry text with soft edges—common in scanned documents or low-quality photos—causes OCR engines to misidentify character boundaries. To learn more about optimal image processing for OCR, check our comprehensive guide on OCR Image Optimization Filters.
To apply the sharpen filter, invoke the Sharpen method of the OcrImageInput object:
:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-sharpen-filter.cs
using IronOcr;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply sharpen filter
imageInput.Sharpen();
// Export filtered image
imageInput.SaveAsImages("sharpen.jpg");
Imports IronOcr
' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()
' Add image
Private imageInput = New OcrImageInput("sample.jpg")
' Apply sharpen filter
imageInput.Sharpen()
' Export filtered image
imageInput.SaveAsImages("sharpen.jpg")
When Should I Use the Sharpen Filter?
Use sharpening for slightly out-of-focus images, scanned documents with soft text edges, or photographs taken in poor lighting. Avoid over-sharpening clear text, as this introduces artifacts and reduces accuracy. For extremely blurry scans, combine sharpening with other filters or see our guide on Fixing Low Quality Scans & Images.
Export filtered images using the SaveAsImages method. Below is a before-and-after comparison.
Before
After
How Do I Enhance Resolution for Better OCR?
This filter increases pixel density, improving sharpness and clarity. It helps OCR engines read text in low-resolution images more accurately.
What DPI Should I Target for OCR?
OCR engines perform best at 300 DPI (dots per inch). Lower resolutions cause character misrecognition; higher resolutions slow processing without improving accuracy. IronOCR's enhancement filter intelligently upscales images to optimal DPI levels. For detailed guidance, see our DPI Settings guide.
Invoke the EnhanceResolution method to apply this filter. Default target is 225 DPI:
using IronOcr;
// Create OCR input
var imageInput = new OcrImageInput("low-res-scan.jpg");
// Apply enhance resolution filter with default 225 DPI
imageInput.EnhanceResolution();
// Or specify a custom DPI
imageInput.EnhanceResolution(300);
// Combine with OCR reading
var ocr = new IronTesseract();
var result = ocr.Read(imageInput);
Console.WriteLine($"Extracted text: {result.Text}");
using IronOcr;
// Create OCR input
var imageInput = new OcrImageInput("low-res-scan.jpg");
// Apply enhance resolution filter with default 225 DPI
imageInput.EnhanceResolution();
// Or specify a custom DPI
imageInput.EnhanceResolution(300);
// Combine with OCR reading
var ocr = new IronTesseract();
var result = ocr.Read(imageInput);
Console.WriteLine($"Extracted text: {result.Text}");
Imports IronOcr
' Create OCR input
Dim imageInput As New OcrImageInput("low-res-scan.jpg")
' Apply enhance resolution filter with default 225 DPI
imageInput.EnhanceResolution()
' Or specify a custom DPI
imageInput.EnhanceResolution(300)
' Combine with OCR reading
Dim ocr As New IronTesseract()
Dim result = ocr.Read(imageInput)
Console.WriteLine($"Extracted text: {result.Text}")
When Does Resolution Enhancement Matter Most?
Resolution enhancement is crucial for:
- Screenshots captured at screen resolution (72-96 DPI)
- Web images downloaded from the internet
- Historical documents scanned at low resolutions
- Fax transmissions with inherently low resolution
The OCR Tesseract Image DPI example provides insights into how DPI affects accuracy across document types.
Before
After
How Do I Remove Noise from Images?
Denoising filters reduce unwanted artifacts in images. Noise reduction isolates text from background interference, producing cleaner and more accurate OCR results.
What's the Difference Between 2x2 and 3x3 Morphology?
Morphology size determines denoising strength. A 2x2 morphology applies gentle noise reduction for minimal artifacts while preserving fine text. The 3x3 morphology provides aggressive noise removal for heavily degraded documents but may affect very small text.
To apply the denoise filter, use the DeNoise method. Default morphology is 2x2. Pass 'true' for 3x3 morphology:
using IronOcr;
// Load noisy document
var imageInput = new OcrImageInput("noisy-scan.pdf");
// Apply denoise filter with default 2x2 morphology
imageInput.DeNoise();
// Apply stronger denoising with 3x3 morphology
imageInput.DeNoise(true);
// Combine with other filters for severely degraded images
imageInput.DeNoise()
.Sharpen()
.EnhanceResolution(300);
// Process with OCR
var ocr = new IronTesseract();
var result = ocr.Read(imageInput);
// Check confidence levels
foreach (var page in result.Pages)
{
Console.WriteLine($"Page confidence: {page.Confidence}%");
}
using IronOcr;
// Load noisy document
var imageInput = new OcrImageInput("noisy-scan.pdf");
// Apply denoise filter with default 2x2 morphology
imageInput.DeNoise();
// Apply stronger denoising with 3x3 morphology
imageInput.DeNoise(true);
// Combine with other filters for severely degraded images
imageInput.DeNoise()
.Sharpen()
.EnhanceResolution(300);
// Process with OCR
var ocr = new IronTesseract();
var result = ocr.Read(imageInput);
// Check confidence levels
foreach (var page in result.Pages)
{
Console.WriteLine($"Page confidence: {page.Confidence}%");
}
Imports IronOcr
' Load noisy document
Dim imageInput As New OcrImageInput("noisy-scan.pdf")
' Apply denoise filter with default 2x2 morphology
imageInput.DeNoise()
' Apply stronger denoising with 3x3 morphology
imageInput.DeNoise(True)
' Combine with other filters for severely degraded images
imageInput.DeNoise() _
.Sharpen() _
.EnhanceResolution(300)
' Process with OCR
Dim ocr As New IronTesseract()
Dim result = ocr.Read(imageInput)
' Check confidence levels
For Each page In result.Pages
Console.WriteLine($"Page confidence: {page.Confidence}%")
Next
How Do I Know If My Image Needs Denoising?
Look for these noise indicators:
- Random speckles or dots on the background
- Salt-and-pepper noise from poor scanning
- Graininess from high ISO photography
- Background texture from recycled paper
For automatic noise detection, explore our Filter Wizard.
Before
After
How Do I Use the Dilate Filter?
Dilation expands bright regions in images. It thickens text, making it more prominent and easier for OCR software to interpret.
When Should I Apply Dilation to Text?
Dilation works best with thin or broken text characters found in:
- Old typewriter documents with inconsistent ink
- Faded receipts and thermal paper printouts
- Documents with hairline fonts
- Over-compressed text in image formats
Dilation fills small gaps within characters and strengthens weak stroke connections. This prevents OCR engines from misinterpreting broken characters as multiple symbols.
To apply the dilation filter, use the Dilate method. Default morphology is 2x2; pass 'true' for 3x3:
using IronOcr;
// Create OCR engine
var ocrTesseract = new IronTesseract();
// Apply dilate filter
var imageInput = new OcrImageInput("thin-text.jpg");
imageInput.Dilate();
// For more aggressive dilation
imageInput.Dilate(true);
// Practical example for faded receipt processing
var receiptInput = new OcrImageInput("faded-receipt.jpg");
receiptInput.Dilate()
.DeNoise()
.EnhanceResolution(300);
// Configure for better receipt reading
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;
ocrTesseract.Configuration.ReadBarCodes = true;
// Perform OCR
var result = ocrTesseract.Read(receiptInput);
using IronOcr;
// Create OCR engine
var ocrTesseract = new IronTesseract();
// Apply dilate filter
var imageInput = new OcrImageInput("thin-text.jpg");
imageInput.Dilate();
// For more aggressive dilation
imageInput.Dilate(true);
// Practical example for faded receipt processing
var receiptInput = new OcrImageInput("faded-receipt.jpg");
receiptInput.Dilate()
.DeNoise()
.EnhanceResolution(300);
// Configure for better receipt reading
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;
ocrTesseract.Configuration.ReadBarCodes = true;
// Perform OCR
var result = ocrTesseract.Read(receiptInput);
Imports IronOcr
' Create OCR engine
Dim ocrTesseract As New IronTesseract()
' Apply dilate filter
Dim imageInput As New OcrImageInput("thin-text.jpg")
imageInput.Dilate()
' For more aggressive dilation
imageInput.Dilate(True)
' Practical example for faded receipt processing
Dim receiptInput As New OcrImageInput("faded-receipt.jpg")
receiptInput.Dilate() _
.DeNoise() _
.EnhanceResolution(300)
' Configure for better receipt reading
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock
ocrTesseract.Configuration.ReadBarCodes = True
' Perform OCR
Dim result = ocrTesseract.Read(receiptInput)
What Are Common Issues with Over-Dilation?
Excessive dilation may cause:
- Character bleeding where adjacent letters merge
- Loss of internal details (holes in 'e' or '8')
- Reduced accuracy for bold text
Monitor results and adjust accordingly. For documents with mixed text weights, use our image quality correction filters selectively.
Before
After
How Do I Apply the Erode Filter?
Erosion reduces bright region sizes in images, refining thick or distorted characters and improving character separation.
Why Does Erosion Help with Thick Text?
Erosion thins text strokes and separates touching characters. This filter excels with:
- Over-inked printed documents
- Photocopies with character bleeding
- Bold text that appears merged
- Low-quality fax transmissions
Careful erosion restores character separation and improves individual letter recognition, preventing entire words from being misread.
Use the Erode method to apply this filter. Default morphology is 2x2; pass 'true' for 3x3:
using IronOcr;
// Create OCR instance
var ocrTesseract = new IronTesseract();
// Load image with thick text
var imageInput = new OcrImageInput("thick-text.jpg");
// Apply erode filter
imageInput.Erode();
// Stronger erosion for heavily bleeding text
imageInput.Erode(true);
// Example: Processing a poor-quality photocopy
var photocopyInput = new OcrImageInput("thick-text-photocopy.pdf");
// Apply erosion followed by sharpening for best results
photocopyInput.Erode()
.Sharpen()
.EnhanceResolution(300);
// Configure OCR for better accuracy
ocrTesseract.Configuration.BlackListCharacters = "~`@#$%^&*()_+-={}[]|\\:\";<>?,./";
ocrTesseract.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
var ocrResult = ocrTesseract.Read(photocopyInput);
// Extract with confidence check
var highConfidenceText = ocrResult.Blocks
.Where(b => b.Confidence > 90)
.Select(b => b.Text);
using IronOcr;
// Create OCR instance
var ocrTesseract = new IronTesseract();
// Load image with thick text
var imageInput = new OcrImageInput("thick-text.jpg");
// Apply erode filter
imageInput.Erode();
// Stronger erosion for heavily bleeding text
imageInput.Erode(true);
// Example: Processing a poor-quality photocopy
var photocopyInput = new OcrImageInput("thick-text-photocopy.pdf");
// Apply erosion followed by sharpening for best results
photocopyInput.Erode()
.Sharpen()
.EnhanceResolution(300);
// Configure OCR for better accuracy
ocrTesseract.Configuration.BlackListCharacters = "~`@#$%^&*()_+-={}[]|\\:\";<>?,./";
ocrTesseract.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
var ocrResult = ocrTesseract.Read(photocopyInput);
// Extract with confidence check
var highConfidenceText = ocrResult.Blocks
.Where(b => b.Confidence > 90)
.Select(b => b.Text);
Imports IronOcr
' Create OCR instance
Dim ocrTesseract As New IronTesseract()
' Load image with thick text
Dim imageInput As New OcrImageInput("thick-text.jpg")
' Apply erode filter
imageInput.Erode()
' Stronger erosion for heavily bleeding text
imageInput.Erode(True)
' Example: Processing a poor-quality photocopy
Dim photocopyInput As New OcrImageInput("thick-text-photocopy.pdf")
' Apply erosion followed by sharpening for best results
photocopyInput.Erode() _
.Sharpen() _
.EnhanceResolution(300)
' Configure OCR for better accuracy
ocrTesseract.Configuration.BlackListCharacters = "~`@#$%^&*()_+-={}[]|\:"";<>?,./"
ocrTesseract.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
Dim ocrResult = ocrTesseract.Read(photocopyInput)
' Extract with confidence check
Dim highConfidenceText = ocrResult.Blocks _
.Where(Function(b) b.Confidence > 90) _
.Select(Function(b) b.Text)
How Do I Balance Erosion with Text Readability?
Finding the right erosion level requires careful testing:
- Start with default 2x2 morphology
- Test on representative document samples
- Check that punctuation marks remain visible
- Ensure thin fonts don't become broken
For documents with mixed text weights, see our advanced configuration options.
Before
After
How Do I Save Filtered Images as Searchable PDFs?
IronOCR lets you save modified PDFs with filters applied or in their original state. The SaveAsSearchablePdf method's second parameter determines whether to save with filters.
What's the Benefit of Preserving Filter Changes?
Preserving filter changes offers several advantages:
- Creates cleaner, more readable documents
- Maintains consistency across document batches
- Provides visual confirmation of text quality improvements
- Enables quality control comparisons
Creating searchable PDFs embeds an OCR text layer while maintaining visual appearance. Learn more in our guide on creating searchable PDFs.
using IronOcr;
var ocr = new IronTesseract();
var ocrInput = new OcrInput();
// Load a PDF file
ocrInput.LoadPdf("invoice.pdf");
// Apply multiple filters for comprehensive improvement
ocrInput.ToGrayScale()
.DeNoise()
.Sharpen()
.EnhanceResolution(300);
// Perform OCR
OcrResult result = ocr.Read(ocrInput);
// Save the result as a searchable PDF with filters applied
result.SaveAsSearchablePdf("outputFiltered.pdf", true);
// Or save without filters to preserve original appearance
result.SaveAsSearchablePdf("outputOriginal.pdf", false);
// Export to other formats
result.SaveAsTextFile("extracted-text.txt");
result.SaveAsHocrFile("output.html");
using IronOcr;
var ocr = new IronTesseract();
var ocrInput = new OcrInput();
// Load a PDF file
ocrInput.LoadPdf("invoice.pdf");
// Apply multiple filters for comprehensive improvement
ocrInput.ToGrayScale()
.DeNoise()
.Sharpen()
.EnhanceResolution(300);
// Perform OCR
OcrResult result = ocr.Read(ocrInput);
// Save the result as a searchable PDF with filters applied
result.SaveAsSearchablePdf("outputFiltered.pdf", true);
// Or save without filters to preserve original appearance
result.SaveAsSearchablePdf("outputOriginal.pdf", false);
// Export to other formats
result.SaveAsTextFile("extracted-text.txt");
result.SaveAsHocrFile("output.html");
Imports IronOcr
Dim ocr As New IronTesseract()
Dim ocrInput As New OcrInput()
' Load a PDF file
ocrInput.LoadPdf("invoice.pdf")
' Apply multiple filters for comprehensive improvement
ocrInput.ToGrayScale() _
.DeNoise() _
.Sharpen() _
.EnhanceResolution(300)
' Perform OCR
Dim result As OcrResult = ocr.Read(ocrInput)
' Save the result as a searchable PDF with filters applied
result.SaveAsSearchablePdf("outputFiltered.pdf", True)
' Or save without filters to preserve original appearance
result.SaveAsSearchablePdf("outputOriginal.pdf", False)
' Export to other formats
result.SaveAsTextFile("extracted-text.txt")
result.SaveAsHocrFile("output.html")
How Do I Choose Between Filtered and Original PDFs?
Save with filters (true) when:
- Original document quality is poor
- Consistent appearance across documents is needed
- Filtered version significantly improves readability
- Archiving documents for long-term storage
Save without filters (false) when:
- Preserving original appearance is legally required
- Color information is important
- Document authenticity must be maintained
- Filters are only needed for OCR accuracy
For advanced PDF processing options, explore our PDF OCR Text Extraction guide. For optimal filter combinations, see the Filter Wizard tutorial.
Frequently Asked Questions
What image filters can improve OCR accuracy in C#?
IronOCR provides five essential image correction filters: sharpen, enhance resolution, denoise, dilate, and erode. These filters preprocess images to significantly improve OCR accuracy by enhancing text clarity and reducing noise before text extraction.
How do I sharpen a blurry image for better text recognition?
You can sharpen a blurry image using IronOCR's OcrImageInput with a single line of code: new IronOcr.OcrImageInput("sample.png").Sharpen(). This filter increases contrast along edges in the image, creating more defined text boundaries for improved character recognition.
Why does sharpening improve OCR accuracy?
The sharpen filter in IronOCR emphasizes boundaries between text and background by enhancing edge contrast. This is crucial because character recognition algorithms need clear, distinct letter shapes to function properly. Blurry text with soft edges causes OCR engines to misidentify character boundaries.
When should I use the sharpen filter for OCR?
Use IronOCR's sharpening filter for slightly out-of-focus images, scanned documents with soft text edges, or photographs taken in poor lighting. Avoid over-sharpening clear text as this introduces artifacts and reduces accuracy.
What DPI should I target for optimal OCR performance?
IronOCR performs best with images at 300 DPI (dots per inch). Lower resolutions cause character misrecognition, while higher resolutions slow processing without improving accuracy. Use the enhance resolution filter to increase pixel density in low-resolution images.
Can I export filtered images after applying corrections?
Yes, IronOCR allows you to export filtered images using the SaveAsImages method. This enables you to view before-and-after comparisons of your image corrections and verify the improvements before running OCR.
What is the minimal workflow for applying image filters?
The minimal workflow with IronOCR involves 5 steps: download the library, import your PDF or images, apply desired filters (sharpen, enhance resolution, denoise, dilate, erode), export the corrected image for viewing, and use the Read method for OCR processing.

