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.
Use IronOCR's OcrImageInput to sharpen a blurry image with a single line of code. This example demonstrates image enhancement for accurate OCR.
-
1Install IronOCR with NuGet Package Manager
-
2Copy and run this code snippet.
new IronOcr.OcrImageInput("sample.png").Sharpen().SaveAsImages("output.png");New IronOcr.OcrImageInput("sample.png").Sharpen().SaveAsImages("output.png")New IronOcr.OcrImageInput("sample.png").Sharpen().SaveAsImages("output.png") -
3Deploy 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 guide on OCR Image Optimization Filters.
To apply the sharpen filter, invoke the Sharpen method of the OcrImageInput object:
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");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")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}")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}%")
NextImports 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}%")
NextHow 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)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;
using System.Linq;
// 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;
using System.Linq;
// 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
Imports System.Linq
' Create OCR instance
Dim ocrTesseract = New IronTesseract()
' Load image with thick text
Dim 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
Dim 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 "
Dim ocrResult = ocrTesseract.Read(photocopyInput)
' Extract with confidence check
Dim highConfidenceText = ocrResult.Blocks _
.Where(Function(b) b.Confidence > 90) _
.Select(Function(b) b.Text)Imports IronOcr
Imports System.Linq
' Create OCR instance
Dim ocrTesseract = New IronTesseract()
' Load image with thick text
Dim 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
Dim 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 "
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")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 correction filters does IronOCR provide for OCR improvement?
IronOCR offers five essential image correction filters: sharpen, enhance resolution, denoise, dilate, and erode. These filters improve OCR accuracy by enhancing text clarity and reducing noise in images.
How does the sharpen filter improve OCR accuracy?
The sharpen filter increases contrast along edges in the image, creating more defined text boundaries. This enhancement helps OCR engines recognize characters more accurately by emphasizing the separation between text and background.
When should I use the enhance resolution filter?
Enhance resolution is useful for low-resolution images like screenshots, web images, and scanned historical documents. It increases pixel density, improving sharpness and clarity to facilitate more accurate OCR reading.
What is the benefit of using denoising filters?
Denoising filters remove unwanted artifacts and noise from images, helping to isolate text from background interference. This results in cleaner, more accurate OCR outputs.
How does the dilate filter aid OCR processes?
The dilate filter thickens text, making it more prominent in images. This is especially useful for thin or broken text characters, allowing OCR software to interpret them more effectively.
Why would I use the erode filter on scanned documents?
The erode filter reduces the size of bright regions, refining thick or distorted characters and improving character separation. It is beneficial for over-inked, bold text that appears merged in scanned documents.
How can I save a filtered image as a searchable PDF using IronOCR?
You can save modified images as searchable PDFs by using the SaveAsSearchablePdf method in IronOCR. This method allows you to choose whether to save the document with applied filters or in its original state.
What parameters should I consider when choosing between filtered and original PDFs?
Choose filtered PDFs when you need consistent appearance, improved readability, or archiving. Opt for original PDFs when preserving original appearance is legally required, or when maintaining color information and document authenticity is important.
What are common signs that my image needs denoising?
Noise indicators include random speckles, salt-and-pepper noise, graininess from high ISO photography, and background texture that interferes with text clarity.
What typical DPI settings are recommended for optimal OCR results?
OCR engines perform best at 300 DPI. Lower resolutions may lead to character misrecognition, while higher resolutions might slow processing without enhancing accuracy. IronOCR's enhancement filter can upscale images to the optimal DPI level.
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.