Skew correction

When a page is fed to a flatbed scanner (mechanically or manually) or photographed with a smartphone, it is nearly impossible to achieve perfect alignment. As a result, a slight skew (tilt) inevitably occurs in scanned images or photographs.

Skew angle detection and image straightening is critical to the OCR process as it directly affects the reliability and efficiency of segmentation and text extraction. Aspose.OCR offers automated processing algorithms to correct image tilt (deskew) before proceeding to recognition.

Detecting skew angle

To find out the skew angle, use CalcSkewImage or CalcSkewImageFromUri methods of AsposeOCR class.

Skewed image

> Skew angle: 5.9°

Automatic skew correction

To automatically straighten skewed image before recognition, run the image through AutoSkew preprocessing filter or enable skew correction in recognition settings.

Skewed image Deskewed image

Manual skew correction

In rare cases, automatic skew correction may incorrectly determine the angle of the image. This can happen to poor quality photos with significant perspective distortions.

To deal with such situations, you can rotate the image by the specified degree using Rotate preprocessing filter or manually define the skew angle for such images using the setSkew method of recognition settings. The rotation angle is passed in degrees:

  • -360 to 0: rotate counterclockwise;
  • 0 to 360: rotate clockwise.

Image regions preprocessing

Automatic skew correction and manual rotation filters can be applied to specific regions of an image. For example, you can straighten an illustration on a page while leaving the rest of the content unchanged.

To apply a filter to an area, specify its top left corner along with width and height as Rectangle object. If the region is omitted, the filter is applied to the entire image.

Rectangle rectangle = new Rectangle(5, 161, 340, 340);
PreprocessingFilter filters = new PreprocessingFilter();
filters.add(PreprocessingFilter.Rotate(90, rectangle));

Usage scenarios

  • Automatic skew correction is recommended in almost all cases, except for perfectly straight scans.
  • Manual rotation is recommended for:
    • photos of low quality;
    • images with a significant angle of inclination.