Scanned documents often become skewed (slanted) during scanning because of misfeeds or other alignment errors. Skew is the amount of rotation necessary to return an image to horizontal and vertical alignment. Skew is measured in degrees. Deskewing is a process whereby skew is removed by rotating an image by the same amount as its skew but in the opposite direction. This results in a horizontally and vertically aligned image where the text runs across the page rather than at an angle.

When an image is not aligned correctly, optical character recognition (OCR) is more difficult and becomes slower and less accurate. Deskewing the documents beforehand can make the OCR process faster and more accurate.

LEADTOOLS offers functions that handle two-dimensional deskewing, as well as others that handle three-dimensional deskewing. 

Two-Dimensional Deskewing

LEADTOOLS offers the following functionality for automatically straightening scanned documents:


The deskewing functions make it possible to:

Use the L_DeskewBitmapExt function when a lot of rotation may be necessary (as much as 45 degrees in either direction), or when it is desired to specify the maximum angle/resolution of deskewing.

Use the L_DeskewBitmap function to automatically straighten scanned documents of any kind. Images can be rotated by as much as 20 degrees in either direction to remove the skew. It can also be used when performing bank check scanning to obtain more accuracy than provided by the L_DeskewBitmapExt. To perform bank check scanning, send the following flags to the uFlags parameter (DSKW_USE_CHECK_DESKEW| DSKW_USE_CHECK_DESKEW_DETECT_LINES).

Different algorithms can be used when deskewing, as follows:

The following images demonstrate the deskewing of color, grayscale, and 1-bit images.

The original color image is shown in the following figure:

Color original

The deskewed color image is shown in the following figure:

Color deskewed

The original grayscale image is shown in the following figure:

Gray original

The deskewed grayscale image is shown in the following figure:

Gray deskewed

The original 1-bit image is shown in the following figure:

1-bit original

The deskewed 1-bit image is shown in the following figure:

1-bit deskewed

Three-Dimensional Deskewing

Use the L_Keystone function to perform inverse perspective transformation (keystoning) on an image. The L_Keystone function maps a polygon to a rectangle.

Use the L_ManualPerspectiveDeskew function to change an image based on a view perspective equation, taking the depth of the objects into account as well as their relative dimensions. The L_ManualPerspectiveDeskew function maps a polygon to a polygon.

Use the L_PerspectiveDeskew function if there is depth (z-axis) deformation as well as deformation along the x- and y- axes. The L_PerspectiveDeskew function automatically detects a document's corners and then applies the L_Keystone function internally in order to remove the 3D-skew deformation. For best results, the document's boundaries should be inside the captured view and have a different background color than the background of the captured view.

Use the L_PerspectiveBitmap function to map the corners of the image to the corners of a polygon located within the original image.

Help Version 21.0.2021.4.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help