ImageGear .NET - Updated
Pre-Process an Image
User Guide > How to Work with... > OCR > How to... > Pre-Process an Image

Before recognizing an image, API methods can be used to apply some image pre-processing procedures to enhance the quality of an image resulting in more accurate auto-zoning and recognition. This is typically done with the ImGearRecImage.Preprocess Method, which can include any or all of the following steps:

The following properties of ImGearRecPreprocessingSettings Class let you define the behavior of these image enhancement steps:

In addition to these, sometimes image despeckling and resolution enhancement are also performed internally to improve the success of the above transformations.

The Asian Recognition module offers additional settings for automatic deskewing and orientation. See the Asian Recognition Module topic for more details.

Example

Pre-processing an image to deskew it by a set value with the ImGearRecImage.Preprocess Method:

C#
Copy Code
igRecognition.Preprocessing.DeskewMode = ImGearRecDeskewMode.SET;
igRecognition.Preprocessing.SkewAmount = 82;
igRecPage.Image.Preprocess();
VB.NET
Copy Code
igRecognition.Preprocessing.DeskewMode = ImGearRecDeskewMode.[SET]
igRecognition.Preprocessing.SkewAmount = 82
igRecPage.Image.Preprocess()

The image pre-processing methods can also be called one by one. In your code you can use pre-processing methods of ImGearRecImage such as Invert Method, Orient MethodDeskew Method, and Deskew3D Method. When the application calls any of these methods, the appropriate image enhancement step is immediately performed on the image, and the result is available to both the recognition engine and the application. These methods do not have progress monitoring facilities. 

These sections provide a summary of information on each image modification step:

Invert

Image inversion can be done on any image (bitonal, grayscale, or color) within the recognition engine's memory space. Recognition needs black or dark characters on a white or pale background.

The Invert Method immediately inverts a whole single image - or a specified rectangle within it. This method ignores the image inversion mode setting. The inverted image replaces the original image and is available to the recognition engine and the application.

An image inversion mode setting is made with the ImGearRecPreprocessingSettings.InversionMode Property, taking values from ImGearRecInvertMode Enumeration. These are:

This mode-induced inversion is performed when ImGearRecImage.Preprocess Method is called and always acts on the whole image. The inverted image replaces the original one, it keeps its original type (bitonal, grayscale, or color) and format, and is available to the recognition engine and the application.

If auto-inversion is set (AUTO), grayscale or color images undergo an implicit secondary conversion to create a clean bitonal image. If auto-inversion is set and despeckle mode is ON for a bitonal image with over 280 dpi, a despeckled bitonal image is created. Detecting whether inversion is needed or not is done on the bitonal image - the despeckled image, if available. These bitonal images are not available to the application. If the recognition engine decides inversion is needed, the whole original image is inverted.

Deskew

Image deskewing can be done on any image type (bitonal, grayscale, or color), either automatically or with a programmed value. A deskewed image should increase auto-zoning and recognition accuracy.

The Deskew Method immediately deskews a whole single image in the recognition engine's memory space by an amount defined in the method itself - up to 30 degrees. The DetectSkew Method can be used to detect the amount of skew in an image.

The Deskew Method ignores the DeskewMode Property and SkewAmount Property set in ImGearRecPreprocessingSettings Class. The deskewed image replaces the original image, retaining its type and format, and is available to the recognition engine and the application.

A deskewing mode setting is made with DeskewMode Property, taking values from ImGearRecDeskewMode Enumeration. These are:

The skew value to be applied for SET is defined with SkewAmount Property. The value needed here can be obtained by ImGearRecImage.DetectSkew Method.

This mode-induced deskewing is performed when ImGearRecImage.Preprocess Method is called. The deskewed image replaces the original one; it keeps its original type and format and is available to the recognition engine and the application.

When AUTO is set, grayscale or color images undergo an implicit secondary conversion to create a clean but hidden bitonal image. If AUTO is set and despeckle mode is ON for a bitonal image with over 280 dpi, a hidden, despeckled bitonal image is created. Skew detection is done on the bitonal image - the despeckled image, if available. These hidden bitonal images are not available to the application. The detected deskew value is applied to the original image.

3D Deskew

The 3D deskew feature performs a 3-dimensional deskew on a page. This is useful for correcting skew and perspective distortion common in images taken by a digital camera. In these distorted images, parallel text lines are transformed to be horizontal and column edges are transformed to be vertical. The 3D Deskew algorithm does NOT detect that a page is upside down, so an image with this orientation may remain that way after 3D deskew has been performed.

Similar to the standard 2-dimensional deskew, 3D deskew can be applied in two different ways; either indirectly as part of the ImGearRecImage.Preprocess Method, or directly by the Deskew3D Method. A value has been added to the ImGearRecDeskewMode Enumeration to enable 3D deskew during preprocessing. For immediate correction, the new ImGearRecImage.Deskew3D Method can be used.

The 3D deskew algorithm does require a minimum number of characters, text lines and column edges to be successful. A column edge is defined as the beginning and/or end of consecutive text lines that have identical vertical positions (i.e. the left edge of a column aligned left or both edges of a justified column). The minimal quantities are approximately 10 text lines and the edges of two columns or both edges of a single, justified column.

3D deskew is not supported for images with Asian languages. If any Asian language is set for recognition before pre-processing, 3D deskew will not be available.

Rotate and Flip

Image rotation in multiples of 90º can be done on any image type (bitonal, grayscale, or color).

The method ImGearRecImage.Orient Method immediately rotates and/or flips a whole single image in the recognition engine's memory space. Seven combinations of rotation and flipping are available. This method ignores the image rotation mode setting of the recognition engine. The transformed image replaces the original image, keeping its type and format. It remains in the recognition engine's memory space, but is available to the application.

A rotation mode setting is made with OrientationMode, taking values from ImGearRecOrientationMode. These are:

This mode-induced rotation is performed whenever ImGearRecImage.Preprocess Method is called. When a fixed value is given (e.g., LEFT), the original image is rotated.

When AUTO is set, grayscale or color images undergo an implicit secondary conversion to create a clean bitonal image. If AUTO is set and despeckle mode is ON for a bitonal image with over 280 dpi, a despeckled bitonal image is created. Orientation detection is done on the bitonal image - the despeckled image, if available. This bitonal image is not available to the application. The required rotation is performed on the original image. In both cases, the original rotated image remains in the recognition engine's memory space and is available to the application.

Despeckle

Image despeckling relates to bitonal images. These may be imported as bitonal or may be generated, explicitly or implicitly, from grayscale or color images. Image despeckling can improve the quality of auto-zoning, recognition, and the automatic pre-processing transformations: the detection of inverted characters, skew, and orientation is more reliable when run on a despeckled bitonal image.

The method ImGearRecImage.Despeckle Method immediately despeckles a single bitonal image in the recognition engine's memory space. This functions independently of the despeckle mode setting and the resolution of the original image. The transformed image replaces the original image, keeping its format, and is available to the application.

An image despeckling mode setting is given by DespeckleMode Property, with Boolean values true and false (default: true). This mode setting influences bitonal images with a resolution of 280 dpi or greater. This mode setting is applied whenever any of the following methods are called:

When a grayscale or color image is converted to bitonal, it usually results in a cleaned image. This can be influenced by the values in SecondaryReductionMode Property and ReductionThreshold Property.

With these mode-induced transformations, the cleaned or despeckled bitonal image exists in parallel with the original one and is not available to the application. 

Enhance Resolution

Resolution enhancement may be performed internally during image conversions. It involves a doubling of the resolution of a bitonal image resulting from an implicit secondary image conversion from grayscale or color. The doubling is performed on the basis of information available from the greater pixel depth in grayscale and color images. The resulting bitonal image exists in parallel with the original image, and is not available to the application.

The application has no control over when resolution doubling is done, only on whether and how it is done. The ResEnhancementMode Property accepts one of three settings from ImGearRecResEnhancementMode Enumeration:

Detect Blank Page

Blank page detection can be performed on any image (bitonal, grayscale, or color) within the recognition engine's memory space. The DetectBlankPage Method will consider an image blank if there is a small percentage of noise, especially noise around the edge of the image usually created as a result of scanning.

The DetectBlankPage Method will return true if the image is blank, or false if any text or graphics are found on the page. The image will not be modified by this process.