How to Correct Images Using Filters for Reading
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.
Get started with IronOCR
Start using IronOCR in your project today with a free trial.
How to Correct Images Using Filters for Reading
- 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
- Utilize the
Read
method for OCR processing
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")
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.
Before
After
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()
Before
After
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()
Before
After
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()
Before
After
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()
Before
After