L_AutoBinarizeBitmap

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT EXT_FUNCTION L_AutoBinarizeBitmap(pBitmap, uFactor, uFlags)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_UINT uFactor;

/* threshold factor */

L_UINT uFlags;

/* flags */

Applies binary segmentation to a bitmap automatically.

This feature is available in version 16 or higher.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap having binary segmentation applied automatically.

uFactor

Threshold Factor. The meaning of this factor depends on which type of thresholding is being used. For more information see the description of the uFlags parameter.

uFlags

Flags that indicate the type of pre-processing to perform on the bitmap and the type of thresholding to use. You can use a bitwise OR (|) to specify one flag from each group.

 

The following flags indicate the type of pre-processing to perform on the bitmap:

 

Value

Meaning

 

AUTO_BINARIZE_PRE_AUTO

[0x00000000] Perform automatic pre-processing. This is the default value.

 

AUTO_BINARIZE_NO_PRE

[0x00000001] Do not perform pre-processing.

 

AUTO_BINARIZE_PRE_BG_ELIMINATION

[0x00000002] Eliminate the background of the bitmap but keep the key features, such as text.

 

AUTO_BINARIZE_PRE_LEVELING

[0x00000004] Perform automatic color leveling.

 

The following flags indicate type of threshold to use:

 

Value

Meaning

 

AUTO_BINARIZE_THRESHOLD_AUTO

[0x00000000] Perform automatic thresholding. This is the default value.

 

AUTO_BINARIZE_THRESHOLD_USER

[0x00000010] Let the user choose the threshold value, to be passed in uFactor. Valid values range from 0 to 255.

 

AUTO_BINARIZE_THRESHOLD_PERCENTILE

[0x00000020] Perform percentile thresholding. In this case uFactor is the percentage of black pixels at which to perform thresholding, expressed in hundredths of a percent. For example, 500 means 5 percent. Valid values range from 0 to 10000.

 

AUTO_BINARIZE_THRESHOLD_MEDIAN

[0x00000040] Perform median thresholding.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

AutoBinarize coverts a colored image into a bitonal image automatically, without losing important image features such as text. This function uses several pre-processing and threshold operations which enable the user to extract the key features of any colored image. It can be adjusted to be suitable for a specific input device,  such as a scanner or camera. It is ideal for making unclear document images more readable. This function is especially useful for improving recognition results (OCR, Barcode, OMR, ICR).

L_AutoBinarizeBitmap options:

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function does not support 12 and 16-bit grayscale and 48 and 64-bit color images. If the image is 12 and 16-bit grayscale and 48 and 64-bit color, the function will not return an error.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

LTIMGCOR

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 / XP/Vista.

See Also

Functions:

L_IntensityDetectBitmap, L_DeskewBitmap, L_DeskewBitmapExt, L_LineRemoveBitmap, L_AutoTrimBitmap, L_BlankPageDetectorBitmap, L_DespeckleBitmap, L_AutoBinaryBitmap, L_HolePunchRemoveBitmap, L_HolesRemovalBitmapRgn, L_BorderRemoveBitmap, L_InvertedTextBitmap, L_DotRemoveBitmap, L_ColorResBitmap, L_ColorLevelBitmap, L_DynamicBinaryBitmap, L_SmoothBitmap, L_InvertBitmap, L_InvertedPageBitmap

Topics:

Raster Image Functions: Filtering Images

 

Processing an Image

 

Raster Image Functions: Document Imaging

 

Raster Image Functions: Processing an Image

 

Removing Noise

 

Cleaning Up 1-Bit Images

 

Raster Image Functions: Cleaning Up 1-Bit Images

 

Raster Image Functions: Doing Color Expansion or Reduction

Example

#if defined (LEADTOOLS_V16_OR_LATER)
L_INT AutoBinarizeBitmapExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */
   /* Load the bitmap, keeping the bits per pixel of the file */
   nRet = L_LoadBitmap (TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\slave.jpg"), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet !=SUCCESS)
      return nRet;
 
   nRet = L_AutoBinarizeBitmap(&LeadBitmap, 0, AUTO_BINARIZE_PRE_AUTO | AUTO_BINARIZE_THRESHOLD_AUTO);
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_SaveBitmap(TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\Result.BMP"), &LeadBitmap, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(LeadBitmap.Flags.Allocated)  
      L_FreeBitmap(&LeadBitmap);  
   return SUCCESS;
}
#endif // LEADTOOLS_V16_OR_LATER