L_AutoZoneBitmap

Summary

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.

Syntax

#include "l_bitmap.h"

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

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap in which the zones will be detected.

pLEADZONE * 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.

L_UINT32 * puCount

Pointer to a variable to be updated with the number of detected zones.

L_UINT32 uFlags

Flags indicating how the function should behave. Combine values when appropriate by using a bitwise OR ( | ). Possible values are:

Value Meaning
Types of zones to detect (At least one is required):
AUTOZONE_DETECT_TEXT [0x0001] Detect text zones.
AUTOZONE_DETECT_GRAPHIC [0x0002] Detect graphic zones.
AUTOZONE_DETECT_TABLE [0x0004] Detect table zones.
AUTOZONE_DETECT_ALL [0x00010007] Detect all zone types (Text, Graphics and Tables).
Allow overlapping among zones (Optional):
AUTOZONE_DONT_ALLOW_OVERLAP [0x0000] Do not allow zones to overlap.
AUTOZONE_ALLOW_OVERLAP [0x0010] Allow zones to overlap.
How to merge text zones (Optional):
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.
Table zone detection options (Optional):
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.
Multi-threading usage (Optional):
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).
Bitmap should be changed so all it contains is text (Optional):
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.
Type of the document needed to be autozoned (Optional):
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.
Type of the document needed to be auto-zoned (Optional):
AUTOZONE_DETECT_VERTICAL_TEXT [0x100000] Set this flag if document image contains vertical text lines.
Detect checkbox zones and the sensitivity of the detection (Optional):
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.
Document contains Asian zones:
AUTOZONE_ASIAN_ZONING [0x200] Detect Asian text (Japanese, Chinese, Korean, etc.)
Document contains handwritten zones
AUTOZONE_ICR_ZONING [0x00000080] Detect handwritten zones

AUTOZONECALLBACK pCallback

Optional callback function for additional processing.

L_VOID * 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.

Returns

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

Comments

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

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

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, &pZones, &count, AUTOZONE_DETECT_TEXT, NULL, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   for (i = 0; i < count; i++) 
   { 
      if (pZones[i].uZoneType == LEAD_ZONE_TYPE_TEXT) 
      { 
         TextZonesCount++; 
      } 
 
      if (pZones[i].uZoneType == LEAD_ZONE_TYPE_GRAPHIC) 
      { 
         GraphicZonesCount++; 
      } 
 
      if (pZones[i].uZoneType == LEAD_ZONE_TYPE_TABLE) 
      { 
         TableZonesCount++; 
         TABLEZONE* pTable = (TABLEZONE*)GlobalLock(pZones[i].pZoneData); 
         CellsCount = pTable->Rows * pTable->Columns; 
         GlobalUnlock(pTable); 
      } 
   } 
 
   nRet = L_FreeZoneData(pZones, count); 
 
   if (nRet != SUCCESS) 
      return nRet; 
 
   if (LeadBitmap.Flags.Allocated) 
      L_FreeBitmap(&LeadBitmap); 
 
   return SUCCESS; 
} 

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

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.