How to Fix Image Orientation for Reading
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.
How to Fix Image Orientation for Reading
- Download a C# library to fix image orientation
- Import the PDF document and images for reading
- Apply desired orientation correction, such as rotation, deskew, and scale
- Export the corrected image for viewing
- Utilize the
Read
method for OCR processing
Install with NuGet
Install-Package IronOcr
Download DLL
Manually install into your project
Install with NuGet
Install-Package IronOcr
Download DLL
Manually install into your project
Start using IronPDF in your project today with a free trial.
Check out IronOCR on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming OCR with C#.
Install-Package IronOcr
Consider installing the IronOCR DLL directly. Download and manually install it for your project or GAC form: IronOcr.zip
Manually install into your project
Download DLLRotate 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")
For convenience, you can export the modified image using the SaveAsImages
method. Below is a comparison of the image before and after rotation.
Before
After
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()
Before
After
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)