Guide to using IronOCR Filters

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

IronOCR provides the tools you need to read images that may need preprocessing in the form of filters. You can choose from a wide array of filters that can manipulate your images to become processable.

Quickstart: Apply Filters to Clean Up OCR Images

In just one simple chain of calls, you can apply DeNoise, Binarize, and Deskew filters to improve scan clarity before OCR. This example shows how easy it is to enhance images using IronOCR’s built-in filters and get started right away.

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.

    using var input = new IronOcr.OcrInput("scan.jpg"); input.DeNoise(true).Binarize().Deskew(45); var result = new IronOcr.IronTesseract().Read(input);
  3. Deploy to test on your live environment

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

List of OCR Image Filters

The following Image filters can really improve performance:

  • Filters to change the Image Orientation
    • Rotate - Rotates images by a number of degrees clockwise. For anti-clockwise, use negative numbers.
    • Deskew - Rotates an image so it is the right way up and orthogonal. This is very useful for OCR because Tesseract's tolerance for skewed scans can be as low as 5 degrees.
    • Scale - Scales OCR input pages proportionally.
  • Filters to manipulate Image Colors
    • Binarize - This image filter turns every pixel black or white with no middle ground. This may improve OCR performance in cases of very low text-to-background contrast.
    • ToGrayScale - This image filter turns every pixel into shades of gray. Unlikely to improve OCR accuracy but may improve speed.
    • Invert - Inverts every color. E.g. White becomes black and vice versa.
    • ReplaceColor - Replaces a color in an image with another color, within a certain threshold.
  • Filters to improve Contrast in an Image
    • Contrast - Increases contrast automatically. This filter often improves OCR speed and accuracy in low-contrast scans.
    • Dilate - Advanced Morphology. Dilation adds pixels to the boundaries of objects in an image. Opposite of Erode.
    • Erode - Advanced Morphology. Erosion removes pixels from object boundaries. Opposite of Dilate.
  • Filters to reduce Image Noise
    • Sharpen - Sharpens blurred OCR Documents and flattens alpha channels to white.
    • DeNoise - Removes digital noise. This filter should only be used in scenarios where noise is expected.
    • DeepCleanBackgroundNoise - Heavy background noise removal. Only use this filter if extreme document background noise is known, as it might reduce OCR accuracy of clean documents and is CPU intensive.
    • EnhanceResolution - Enhances the resolution of low-quality images. This filter is not often needed because OcrInput.MinimumDPI and OcrInput.TargetDPI will automatically catch and resolve low-resolution inputs.

Filter Example and Usage

In the following example, we demonstrate how to apply filters within your code.

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-1.cs
using IronOcr;
using System;

var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("my_image.png");
input.Deskew();

var result = ocr.Read(input);
Console.WriteLine(result.Text);
Imports IronOcr
Imports System

Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("my_image.png")
input.Deskew()

Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel

Debug Filter / What is the filter doing?

If you are having difficulty with reading images or barcodes within your program, there is a way to save an image of a filtered result. This way, you can debug and see exactly what each filter does and how it is manipulating your image.

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-2.cs
using IronOcr;
using System;

var file = "skewed_image.tiff";
var ocr = new IronTesseract();
using var input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(file, pageindices);
// Here we apply the filter: Deskew
input.Deskew();

// Save the input with filter(s) applied
input.SaveAsImages("my_deskewed");

// We read, then print the text to the console
var result = ocr.Read(input);
Console.WriteLine(result.Text);
Imports IronOcr
Imports System

Private file = "skewed_image.tiff"
Private ocr = New IronTesseract()
Private input = New OcrInput()
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames(file, pageindices)
' Here we apply the filter: Deskew
input.Deskew()

' Save the input with filter(s) applied
input.SaveAsImages("my_deskewed")

' We read, then print the text to the console
Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel

Filter Use Cases

Rotate

API Reference

Filter Explanation

Rotate is a filter used to manually set a known rotation to an image to get it closest to being straight. IronOCR has functionality to run Deskew(), however, the degree of tolerance for this is rather narrow and is best used for images that are almost perfectly straight (within 15 degrees or so). For input images that are 90 degrees off, or upside down, we should call Rotate().

Use-Case Code Example

This is an example of calling Rotate to correct an upside-down image:

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-3.cs
using IronOcr;
using System;

var image = "screenshot.png";
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);

// Rotate 180 degrees because image is upside-down
input.Rotate(180);

// Read image into variable: result
var result = ocr.Read(input);

// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System

Private image = "screenshot.png"
Private ocr = New IronTesseract()
Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)

' Rotate 180 degrees because image is upside-down
input.Rotate(180)

' Read image into variable: result
Dim result = ocr.Read(input)

' Example print to console
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel
BeforeInput.Rotate(180)`` AfterInput.Rotate(180)``
Screenshot related to Use-Case Code Example Screenshot Rotated related to Use-Case Code Example

Deskew

API Reference

Filter Explanation

Uses a Hough Transform to attempt to straighten an image within certain degrees of tolerance. This is important for images that are not completely straight because a tilted document may result in a misread.

Por favor notaThis method returns a boolean, which is true if the filter was applied, and false if it failed to apply due to not being able to detect image orientation. This will fail if the page has no contents to define orientation.

Use-Case Code Example

This is an example of calling Deskew to correct a skewed image:

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-4.cs
using IronOcr;
using System;

var image = @"paragraph_skewed.png";
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);

// Apply deskew with 15 degree snap
bool didDeskew = input.Deskew(15);
if (didDeskew)
{
    // Read image into variable: result
    var result = ocr.Read(input);
    Console.WriteLine(result.Text);
}
else
{
    Console.WriteLine("Deskew not applied because Image Orientation could not be determined.");
}
Imports IronOcr
Imports System

Private image = "paragraph_skewed.png"
Private ocr = New IronTesseract()
Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)

' Apply deskew with 15 degree snap
Dim didDeskew As Boolean = input.Deskew(15)
If didDeskew Then
	' Read image into variable: result
	Dim result = ocr.Read(input)
	Console.WriteLine(result.Text)
Else
	Console.WriteLine("Deskew not applied because Image Orientation could not be determined.")
End If
$vbLabelText   $csharpLabel
BeforeDeskew()`` AfterDeskew()``
Paragraph Skewed related to Use-Case Code Example Paragraph Deskewed related to Use-Case Code Example

Scale

API Reference

Filter Explanation

Scale is a useful image manipulation filter that helps to resize an image using the pixels it already has. This can be used when a barcode is not being scanned because the image is only tens of pixels wide, with each bar as one pixel, or if text is too small with no anti-aliasing.

Por favor notaThere is a sweet-spot for barcode sizes of 1000px x 1000px where barcodes can be read well, which should be considered if your barcode is not being found.

Use-Case Code Example

This is an example of calling Scale to enlarge the gaps between bars in a barcode for scanning:

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-5.cs
using IronOcr;
using System;

var image = @"small_barcode.png";
var ocr = new IronTesseract();

// Optional: This example uses a barcode
ocr.Configuration.ReadBarCodes = true;

using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);

// Apply scale
input.Scale(400); // 400% is 4 times larger

// Read image into variable: result
var result = ocr.Read(input);

// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System

Private image = "small_barcode.png"
Private ocr = New IronTesseract()

' Optional: This example uses a barcode
ocr.Configuration.ReadBarCodes = True

Dim input = New OcrInput()
' Load at least one image
input.LoadImage(image)

' Apply scale
input.Scale(400) ' 400% is 4 times larger

' Read image into variable: result
Dim result = ocr.Read(input)

' Example print to console
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel
BeforeScale()`` AfterScale()``
C Sharp Ocr Image Filters 1 related to Use-Case Code Example C Sharp Ocr Image Filters 2 related to Use-Case Code Example

Binarize

API Reference

Filter Explanation

The Binarize filter classifies all pixels in an image as either black or white, depending on an adaptive algorithm. This removes all colors and separates the background into a flat white, with anything recognized as text colored a full black for easy reading.

Use-Case Code Example

This is an example of calling Binarize to align colored text and remove background colors and noise:

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-6.cs
using IronOcr;
using System;

var image = @"no-binarize.jpg";
var ocr = new IronTesseract();

using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);

// Apply Binarize
input.Binarize();

// Read image into variable: result
var result = ocr.Read(input);

// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System

Private image = "no-binarize.jpg"
Private ocr = New IronTesseract()

Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)

' Apply Binarize
input.Binarize()

' Read image into variable: result
Dim result = ocr.Read(input)

' Example print to console
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel
BeforeBinarize()`` AfterBinarize()``
No Binarize related to Use-Case Code Example After Binarize related to Use-Case Code Example

Invert

API Reference

Filter Explanation

IronOCR reads best when the image is black text on a white background. The Invert filter is used to achieve this by inverting all colors on an image.

Use-Case Code Example

This is an example of calling Invert to turn white on black into black on white:

:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-7.cs
using IronOcr;
using System;

var image = @"before-invert.png";
var ocr = new IronTesseract();

using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);

// Apply Invert
input.Invert(true);

// Read image into variable: result
var result = ocr.Read(input);

// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System

Private image = "before-invert.png"
Private ocr = New IronTesseract()

Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)

' Apply Invert
input.Invert(True)

' Read image into variable: result
Dim result = ocr.Read(input)

' Example print to console
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel
Before After
Before Invert related to Use-Case Code Example After Invert related to Use-Case Code Example

Preguntas Frecuentes

¿Cómo pueden los filtros de imagen mejorar la precisión del OCR en C#?

Los filtros de imagen en IronOCR pueden preprocesar las imágenes para mejorar su calidad, mejorando así la precisión del OCR. Filtros como Binario y Contraste aumentan la legibilidad ajustando colores y contrastes, mientras que Rotar y Desviación corrigen la orientación de la imagen.

¿Qué filtros están disponibles para corregir la orientación de la imagen?

IronOCR proporciona filtros de Rotar y Desviación para corregir problemas de orientación de imágenes. Rotar permite el ajuste manual de ángulos de imagen, mientras que Desviación endereza automáticamente las imágenes ligeramente inclinadas.

¿Cómo afecta el filtro Binario al preprocesamiento de la imagen?

El filtro Binario en IronOCR convierte los píxeles de la imagen en blanco y negro, lo que elimina los colores de fondo y mejora la visibilidad del texto, mejorando particularmente la precisión del OCR en condiciones de bajo contraste.

¿Cuándo es apropiado usar filtros de reducción de ruido?

Los filtros de reducción de ruido como Afilar y ReducirRuido deben usarse cuando hay ruido digital en las imágenes. Estos filtros limpian la imagen, haciendo que el texto sea más claro para obtener mejores resultados de OCR en IronOCR.

¿Puede la mejora de la resolución de la imagen afectar el rendimiento del OCR?

Sí, usar el filtro MejorarResolución puede mejorar el rendimiento del OCR al aumentar la resolución de imágenes de baja calidad. Aunque las configuraciones por defecto de DPI Mínimo y DPI Objetivo de IronOCR a menudo son suficientes, el filtro puede proporcionar una mejora adicional de la resolución si es necesario.

¿Qué papel juegan los filtros de manipulación de color en el OCR?

Los filtros de manipulación de color como Invertir, A Escala de Grises y Binario en IronOCR ajustan los colores de la imagen para aumentar la legibilidad del texto. Invertir cambia los esquemas de color, A Escala de Grises convierte las imágenes a escala de grises, y Binario reduce las imágenes a blanco y negro.

¿Cuál es la diferencia entre los filtros de Contraste y Afilar?

El filtro de Contraste en IronOCR aumenta la diferencia entre las áreas claras y oscuras, mejorando la claridad del texto, mientras que el filtro Afilar mejora los bordes para hacer que el texto sea más distintivo, ayudando a un mejor reconocimiento de OCR.

¿Cómo guardar y depurar imágenes filtradas en IronOCR?

Para guardar y depurar imágenes filtradas en IronOCR, use la función SaveAsImages después de aplicar filtros. Esto ayuda a visualizar los efectos de los filtros y asegura que los pasos de preprocesamiento hayan mejorado la calidad de la imagen para el OCR.

¿Cuáles son los filtros morfológicos avanzados disponibles en IronOCR?

IronOCR ofrece filtros morfológicos avanzados como Dilatar y Erosionar. Dilatar agrega píxeles a los límites de los objetos para mejorar las características, mientras que Erosionar los elimina, ambos utilizados para aclarar detalles de imagen para mejorar la precisión del OCR.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
Revisado por
Jeff Fritz
Jeffrey T. Fritz
Gerente Principal de Programas - Equipo de la Comunidad .NET
Jeff también es Gerente Principal de Programas para los equipos de .NET y Visual Studio. Es el productor ejecutivo de la serie de conferencias virtuales .NET Conf y anfitrión de 'Fritz and Friends', una transmisión en vivo para desarrolladores que se emite dos veces a la semana donde habla sobre tecnología y escribe código junto con la audiencia. Jeff escribe talleres, presentaciones, y planifica contenido para los eventos de desarrolladores más importantes de Microsoft, incluyendo Microsoft Build, Microsoft Ignite, .NET Conf y la Cumbre de Microsoft MVP.
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado