#include "l_bitmap.h"

L_LTIMGCOR_API L_INT EXT_FUNCTION L_AutoZoneBitmap(pBitmap, phZones, puCount, uFlags, pCallback, pUserData)

pBITMAPHANDLE pBitmap; pointer to the bitmap handle
pLEADZONE * phZones; pointer of a handle to be updated with the detected zones
L_UINT32 * puCount; the count of detected zones
L_UINT32 uFlags; flags
AUTOZONECALLBACK pCallback; optional callback function
L_VOID * pUserData; pointer to more parameters for the callback

Automatically detects different zone types (Text, Graphics and Tables) in an image. Classifying by types, improves the recognition results from OCR pre-processing. This function is useful for any application that needs to automatically separate images, tables and text within mixed raster content (MRC) images.

Parameter Description
pBitmap Pointer to the bitmap handle referencing the bitmap in which the zones will be detected.
phZones Pointer to a handle to be updated with the detected zones. To retrieve data about the detected zones cast the phZones to pLEADZONE and call the GlobalLock function.
puCount Pointer to a variable to be updated with the number of detected zones.
uFlags Flags indicating how the function should behave. Combine values when appropriate by using a bitwise OR (|). Possible values are:
Flags indicating which types of zones to detect: (At least one is required)
Value Meaning
AUTOZONE_DETECT_TEXT [0x0001] Detect text zones.
AUTOZONE_DETECT_GRAPHIC [0x0002] Detect graphic zones.
AUTOZONE_DETECT_TABLE [0x0004] Detect table zones.
AUTOZONE_DETECT_ALL [0x0007] Detect all zone types (Text, Graphics and Tables).
Flags indicating whether to allow overlapping among zones: (Optional)
Value Meaning
AUTOZONE_DONT_ALLOW_OVERLAP [0x0000] Do not allow zones to overlap.
AUTOZONE_ALLOW_OVERLAP [0x0010] Allow zones to overlap.
Flags indicating how to merge text zones: (Optional)
Value Meaning
AUTOZONE_ACCURATE_ZONES [0x0000] Do not merge text zones and keep them separated (paragraphs).
AUTOZONE_GENERAL_ZONES [0x0100] Merge text zones as much as possible.
Flags indicating options for table zone detection: (Optional)
Value Meaning
AUTOZONE_DONT_RECOGNIZE_ONE_CELL_TABLE [0x0000] Ignore one-cell tables (borders), and detect what is inside.
AUTOZONE_RECOGNIZE_ONE_CELL_TABLE [0x1000] Consider borders as one-cell tables.
AUTOZONE_NORMAL_TABLE (version 17 or later) [0x0000] Use Normal Table Detection.
AUTOZONE_ADVANCED_TABLE (version 17 or later) [0x2000] Use Advanced Table Detection which returns more accurate results and detects complex tables.
AUTOZONE_LINES_RECONSTRUCTION (version 17 or later) [0x4000] Use Line Reconstruction for patterned tables and to connect broken lines.
Flags indicating whether to use multi-threading: (Optional)
Value Meaning
AUTOZONE_USE_MULTITHREADING [0x00000000] Use multi-threading (faster for multi-core CPUs).
AUTOZONE_DONTUSE_MULTITHREADING [0x80000000] Do not use multi-threading (necessary for single-core CPUs).
Flag indicating the bitmap should be changed so all it contains is text: (Optional)
Value Meaning
AUTOZONE_TEXT_DETECTION [0x8000] If set, the function does not return text zones in phZones. Instead, it modifies pBitmap to have text areas only: graphics and tables areas are deleted from the input image.
NOTE: Make a copy of the original image if you want to keep it. When this function is set to AUTOZONE_TEXT_DETECTION, the original image is modified.
Flag indicating the type of the document needed to be autozoned: (Optional)
Value Meaning
AUTOZONE_TEXTBOOK [0x40000] Setting this flag improves zoning book's pages.
AUTOZONE_FAVOR_GRAPHICS [0x400000] This flag is used to improve detecting figure zones in documents.
Flag indicating the type of the document needed to be auto-zoned: (Optional)
Value Meaning
AUTOZONE_DETECT_VERTICAL_TEXT [0x100000] Set this flag if document image contains vertical text lines.
Flag indicating whether to detect checkbox zones and the sensitivity of the detection: (Optional)
Value Meaning
AUTOZONE_DETECT_CHECKBOX [0x10000] Set this flag to detect checkbox zones in documents.
AUTOZONE_CHECKBOX_SENSITIVITY_HIGH [0x00000000] The sensitivity of matching the checkboxes shape is high, and hence, the false negative detections is low.
AUTOZONE_CHECKBOX_SENSITIVITY_LOW [0x200000] The sensitivity of matching the checkboxes shape is low, and hence, the false negative detections is high.
Flag indicating that document contains Asian zones:
Value Meaning
AUTOZONE_ASIAN_ZONING [0x200] Detect Asian text (Japanese, Chinese, Korean, etc.)
pCallback Optional callback function for additional processing.
- If you do not provide a callback function, use NULL as the value of this parameter.
- If you do provide a callback function, use the function pointer as the value of this parameter.
The callback function must adhere to the function prototype described in the AUTOZONECALLBACK Function.
pUserData Void pointer that you can use to pass one or more additional parameters that the callback function needs.
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.
If additional parameters are not needed, pass NULL.


SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


After using this function free phZones by using the L_FreeZoneData function.

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

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_GRAY32_UNSUPPORTED error code if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

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


Win32, x64, Linux.

See Also

Functions: L_FreeZoneData, L_DespeckleBitmap, L_WindowLevel, L_ApplyTransformationParameters, L_GetMarksCenterMassBitmap, L_GetTransformationParameters, L_IsRegMarkBitmap, L_SearchRegMarksBitmap
Topics: Raster Image Functions: Document Imaging
Raster Image Functions: Processing an Image
Processing an Image


Detects the image zones and return the results.

L_INT AutoZoneBitmapExample(L_VOID) 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
   pLEADZONE pZones = NULL; 
   L_UINT32 count = 0; 
   L_INT TextZonesCount = 0; 
   L_INT GraphicZonesCount = 0; 
   L_INT TableZonesCount = 0; 
   L_INT CellsCount = 0; 
   L_UINT i; 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("Clean.tif")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet = L_AutoZoneBitmap(&LeadBitmap, 
   if(nRet !=SUCCESS) 
      return nRet; 
   for(i=0; i<count; i++) 
      if (pZones[i].uZoneType == LEAD_ZONE_TYPE_TEXT) 
      if (pZones[i].uZoneType == LEAD_ZONE_TYPE_GRAPHIC) 
      if (pZones[i].uZoneType == LEAD_ZONE_TYPE_TABLE) 
         TABLEZONE * pTable = (TABLEZONE *)GlobalLock(pZones[i].pZoneData); 
         CellsCount = pTable->Rows * pTable->Columns; 
   nRet = L_FreeZoneData(pZones, count); 
   if(nRet !=SUCCESS) 
      return nRet; 
   return SUCCESS; 

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

LEADTOOLS Raster Imaging C API Help