Cómo corregir la orientación de imágenes para OCR en C# | IronOCR

How to Fix Image Orientation for Reading

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

Fixing image orientation, in the context of image processing, involves making adjustments to an image to ensure it is properly aligned for specific purposes, such as text recognition. IronOcr supports fixing image orientation, including rotation, deskewing, and scaling.

These techniques are essential for preparing images for accurate text recognition, as they ensure that text is correctly oriented, aligned, and appropriately sized for extraction.

Quickstart: Rotate-Deskew-Scale in One Line

Use this simple chain using IronOCR’s OcrInput to rotate, deskew, and scale your image in a single call — get started quickly without boilerplate so your image is prepped for accurate OCR in seconds.

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.

    var result = new IronOcr.OcrInput().LoadImage("skewed.png").Rotate(90).Deskew(45).Scale(150).Let(input => 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


Rotate Image Example

Rotating an image involves changing its orientation by a specific angle (e.g., 90 degrees clockwise or counterclockwise) to ensure that the text or content within the image is upright and correctly aligned.

Pass a degree value to the Rotate method to perform the rotation. A positive degree value will rotate the image clockwise, while a negative degree value will rotate the image counterclockwise.

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

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

// Add image
using var imageInput = new OcrImageInput("paragraph_skewed.png");

// Rotate the image 180 degrees clockwise
imageInput.Rotate(180);

// Export the modified image
imageInput.SaveAsImages("rotate");
Imports IronOcr

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Add image
Private imageInput = New OcrImageInput("paragraph_skewed.png")

' Rotate the image 180 degrees clockwise
imageInput.Rotate(180)

' Export the modified image
imageInput.SaveAsImages("rotate")
$vbLabelText   $csharpLabel

For convenience, you can export the modified image using the SaveAsImages method. Below is a comparison of the image before and after rotation.

Sample image
Rotated image

Deskew Image Example

Deskewing is the process of straightening an image that may be slightly tilted or skewed. It corrects any slant or misalignment, ensuring that the text or content appears horizontally aligned.

To apply deskewing to the image, use the Deskew method. This method accepts an integer value that specifies the maximum angle of skew to correct. Higher values may provide more opportunities for correction, but they can result in slower processing and an increased risk of errors, including upside-down pages.

:path=/static-assets/ocr/content-code-examples/how-to/image-orientation-correction-deskew-image.cs
// Apply deskew
imageInput.Deskew();
' Apply deskew
imageInput.Deskew()
$vbLabelText   $csharpLabel
Sample image
deskewed image

Scale Image Example

Scaling involves resizing an image to a specific dimension or aspect ratio. This can be useful to standardize image sizes for more consistent text recognition.

To apply scaling to the image, use the Scale method. The Scale method takes a percentage value, with 100% meaning no effect. The second parameter is the ScaleCropArea, which determines whether associated crop areas should also be scaled proportionally (recommended as 'true').

:path=/static-assets/ocr/content-code-examples/how-to/image-orientation-correction-scale-image.cs
// Apply scale
imageInput.Scale(70);
' Apply scale
imageInput.Scale(70)
$vbLabelText   $csharpLabel

Size comparison

Size comparison
Size comparison

Preguntas Frecuentes

¿Cuáles son los métodos clave para corregir la orientación de la imagen en .NET C#?

En .NET C#, puede corregir la orientación de la imagen utilizando los métodos de IronOCR como Rotate para cambiar el ángulo, Deskew para enderezar imágenes inclinadas, y Scale para redimensionar y asegurar una alineación y reconocimiento de texto adecuado.

¿Cómo ayuda el método Rotate en C# con la orientación de la imagen?

El método Rotate en C# ayuda a ajustar el ángulo de una imagen para asegurar que el texto esté en posición vertical. Al pasar un valor de grado positivo, la imagen gira en el sentido de las agujas del reloj; un valor negativo la rota en sentido contrario.

¿Por qué es importante el descuadre en el procesamiento de imágenes?

El descuadre es crucial en el procesamiento de imágenes, ya que endereza imágenes inclinadas, asegurando la alineación horizontal del texto, lo que mejora la precisión de los resultados del Reconocimiento Óptico de Caracteres (OCR).

¿Cómo puede el escalado afectar el reconocimiento de texto en las imágenes?

Escalar una imagen asegura que todas las partes de la imagen se redimensionen proporcionalmente, lo que ayuda a mantener un tamaño de texto uniforme y mejora la consistencia y precisión del reconocimiento de texto.

¿Puedo aplicar corrección de orientación de imagen a documentos PDF usando C#?

Sí, utilizando IronOCR, puede importar documentos PDF y aplicar correcciones de orientación de imagen como rotación, descuadre y escalado para mejorar el reconocimiento de texto.

¿Cómo puedo exportar imágenes corregidas después del procesamiento en una aplicación .NET?

Después de procesar y corregir las imágenes usando IronOCR, puede exportar las imágenes modificadas utilizando el método SaveAsImages.

¿Qué debo considerar al elegir valores de descuadre para la corrección de imagen?

Al elegir valores de descuadre, considere que valores más altos podrían ofrecer más oportunidades de corrección, pero también podrían ralentizar el procesamiento y potencialmente causar errores, como imágenes boca abajo.

¿Cuál es el proceso para preparar imágenes para OCR en C#?

Preparar imágenes para OCR en C# involucra corregir la orientación usando métodos como Rotate, Deskew y Scale proporcionados por IronOCR, asegurando que el texto esté correctamente alineado y dimensionado para un reconocimiento preciso.

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