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

Download DLL

Download DLL

Manually install into your project

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.

using IronOcr;

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

// Add image
using var imageInput = new OcrImageInput("sample.jpg");
// Apply sharpen filter

// Export filtered image
Imports IronOcr

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Add image
Private imageInput = New OcrImageInput("sample.jpg")
' Apply sharpen filter

' Export filtered image
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.

// Apply enhance resolution filter
' Apply enhance resolution filter
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.

// Apply denoise filter
' Apply denoise filter
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.

// Apply dilate filter
' Apply dilate filter
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.

// Apply erode filter
' Apply erode filter
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.