How to Correct Images Using Filters for Reading

by Chaknith Bin

Image correction filters are digital image processing techniques used to improve the quality and characteristics of an image, particularly for the purpose of enhancing text recognition and extraction. Image correction filters available in IronOcr are sharpen, enhance resolution, denoise, dilate, and erode.

These image correction filters play a critical role in preprocessing images before OCR, as they help optimize the image for accurate text extraction by improving the quality and visibility of the text and reducing unwanted noise or artifacts.


C# NuGet Library for OCR

Install with NuGet

Install-Package IronOcr
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for OCR

Install with NuGet

Install-Package IronOcr
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronOCR on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming OCR with C#.

C# NuGet Library for OCR nuget.org/packages/IronOcr/
Install-Package IronOcr

Consider installing the IronOCR DLL directly. Download and manually install it for your project or GAC form: IronOcr.zip

Manually install into your project

Download DLL

Sharpen Filter Example

This filter increases the contrast along the edges in the image, giving them a more defined appearance. It improves the clarity of text and details, making it easier for OCR software to recognize characters.

To apply the sharpen filter, simply 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");
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")
VB   C#

For convenience, you can export the filtered image using the SaveAsImages method. Below is a comparison of the image before and after applying the sharpening filter.

Sample image
Sharpen filter applied

Enhance Resolution Filter Example

This filter is designed to increase the pixel density of an image, effectively improving its sharpness and clarity. It can be especially useful for enhancing the legibility of text in low-resolution images.

Similarly, you can invoke the EnhanceResolution method to apply the enhanced resolution filter. This method also accepts the desired target, with 225 DPI as the default value.

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-enhance-resolution-filter.cs
// Apply enhance resolution filter
imageInput.EnhanceResolution();
' Apply enhance resolution filter
imageInput.EnhanceResolution()
VB   C#
Sample image
Enhance resolution filter applied

Denoise Filter Example

Denoising filters reduce the level of noise or unwanted artifacts in an image. Noise reduction is crucial for OCR as it helps isolate text from background interference, leading to cleaner and more accurate recognition.

To apply the denoise filter, use the DeNoise method. The default morphology is 2x2, and passing 'true' to the method will enable a 3x3 morphology. Choosing the 3x3 option will apply a stronger denoise algorithm.

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-denoise-filter.cs
// Apply denoise filter
imageInput.DeNoise();
' Apply denoise filter
imageInput.DeNoise()
VB   C#
Sample image
Denoise filter applied

Dilate Filter Example

Dilation is a filter that expands the brighter regions (foreground) in an image. It helps thicken and enhance the text, making it more prominent and easier for OCR software to interpret.

To apply the dilation filter, use the Dilate method. Similar to the DeNoise method, the default morphology is 2x2, and passing 'true' will enable the 3x3 option.

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-dilate-filter.cs
// Apply dilate filter
imageInput.Dilate();
' Apply dilate filter
imageInput.Dilate()
VB   C#
Sample image
Dilter filter applied

Erode Filter Example

Erosion, on the other hand, shrinks or reduces the size of bright regions in an image. This can be useful for refining characters and lines, particularly when they are thick or slightly distorted.

Use the Erode method to apply the erode filter. Similar to the previous two methods, 2x2 is the morphology and passing true will enable the 3x3 option.

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-erode-filter.cs
// Apply erode filter
imageInput.Erode();
' Apply erode filter
imageInput.Erode()
VB   C#
Sample image
Erode filter applied

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.