How to Correct Images Using Filters for Reading

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Apply Sharpen Filter for Clear Text

Use IronOCR's OcrImageInput to sharpen a blurry image with a single line of code. This quick start shows how fast you can enhance image clarity and get ready for accurate OCR with minimal effort.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    new IronOcr.OcrImageInput("sample.png").Sharpen().SaveAsImages("output.png");
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer


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, 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")
$vbLabelText   $csharpLabel

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.

Invoke the EnhanceResolution method to apply the enhanced resolution filter. This method accepts the target DPI, 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()
$vbLabelText   $csharpLabel
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. To apply a stronger denoise algorithm, pass 'true' to enable a 3x3 morphology.

: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()
$vbLabelText   $csharpLabel
Sample image
Denoise filter applied

Dilate Filter Example

Dilation 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. Default morphology is 2x2, and setting 'true' enables 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()
$vbLabelText   $csharpLabel
Sample image
Dilate filter applied

Erode Filter Example

Erosion reduces the size of bright regions in an image, useful for refining characters and lines, especially when they are thick or distorted.

Use the Erode method to apply the erode filter. As with previous methods, default morphology is 2x2, and setting 'true' enables 3x3.

: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()
$vbLabelText   $csharpLabel
Sample image
Erode filter applied

Searchable Pdfs

Other than the options for filtering images, IronOcr gives developers the flexibility of saving the modified PDF with the filters on or off. The SaveAsSearchablePdf method allows a boolean flag to be taken in as the second parameter to determine whether you want to save with filters or not.

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-searchable-pdf.cs
using IronOcr;

var ocr = new IronTesseract();
var ocrInput = new OcrInput();

// Load a PDF file
ocrInput.LoadPdf("invoice.pdf");

// Apply gray scale filter
ocrInput.ToGrayScale();
OcrResult result = ocr.Read(ocrInput);

// Save the result as a searchable PDF with filters applied
result.SaveAsSearchablePdf("outputGrayscale.pdf", true);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Preguntas Frecuentes

¿Cómo mejorar la calidad de imagen para mejores resultados OCR?

Puede mejorar la calidad de la imagen para obtener mejores resultados de OCR usando IronOCR aplicando varios filtros de corrección de imagen como afilar, aumentar resolución, reducir el ruido, dilatar y erosionar. Estos filtros mejoran la claridad del texto y reducen el ruido, facilitando una extracción de texto más precisa.

¿Cuáles son los beneficios de usar filtros de mejora en preprocesamiento de imagen?

Los filtros de mejora en IronOCR incrementan el contraste de los bordes, mejorando la claridad y legibilidad del texto en las imágenes. Esta mejora es crucial para aumentar la precisión del reconocimiento de texto en OCR.

¿Cómo aumento la resolución de una imagen para el procesamiento OCR?

Para aumentar la resolución de una imagen para el procesamiento OCR en IronOCR, use el filtro de mejorar resolución, que incrementa la densidad de píxeles, mejorando la nitidez y claridad de imágenes de baja resolución.

¿Qué pasos debo seguir para reducir el ruido en imágenes antes de OCR?

Para reducir el ruido en imágenes antes de OCR con IronOCR, aplique el método `DeNoise`. Para una reducción de ruido más fuerte, puede habilitar una morfología 3x3 configurando la opción a 'true'.

¿Cómo afecta el filtrado de dilatación la visibilidad del texto en imágenes?

El filtrado de dilatación en IronOCR expande las regiones más brillantes de una imagen, haciendo el texto más prominente y ayudando al proceso de OCR a interpretar los caracteres de manera más efectiva.

¿Cuál es el método para refinar el texto usando filtros de erosión?

Para refinar el texto usando filtros de erosión en IronOCR, use el método `Erode`. Este filtro reduce el tamaño de las regiones brillantes, ayudando a refinar caracteres y líneas gruesas o distorsionadas en la imagen.

¿Qué configuración de DPI se recomienda para mejorar la resolución de la imagen?

La configuración de DPI predeterminada para el filtro de mejorar resolución en IronOCR es de 225 DPI. Sin embargo, puede especificar un DPI diferente según sus necesidades para optimizar la claridad de la imagen.

¿Es posible ajustar la intensidad del efecto de dilatación en IronOCR?

Sí, puede ajustar la intensidad del efecto de dilatación en IronOCR habilitando una morfología 3x3 más fuerte durante la aplicación del filtro de dilatación, lo cual se hace configurando la opción a 'true'.

¿Cómo puedo comenzar a usar filtros de corrección de imagen en .NET C#?

Para comenzar a usar filtros de corrección de imagen en .NET C#, descargue la biblioteca IronOCR a través de NuGet, importe sus imágenes, aplique los filtros deseados como afilar o reducir ruido, y luego exporte las imágenes mejoradas para el procesamiento OCR.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado