L_MrcSegmentBitmapExt

#include "ltsgm.h"

L_INT EXT_FUNCTION L_MrcSegmentBitmapExt (hSegment, pBitmap, pSegOption)

HSEGMENTATION hSegment;

/* segmentation handle */

pBITMAPHANDLE pBitmap;

/* pointer to a bitmap handle */

pSEGMENTEXTOPTIONS pSegOption;

/* pointer to a structure */

Automatically segments the specified bitmap, finding the best segment combination without specifying minimum segment dimensions. This function is available only in the Document/Medical Toolkits.

Parameter

Description

hSegment

An existing segmentation handle. This handle is obtained by calling the L_MrcStartBitmapSegmentation function.

pBitmap

Pointer to the bitmap handle that references the bitmap to be segmented.

pSegOption

Pointer to the SEGMENTEXTOPTIONS structure that controls the automatic segmentation process. This cannot be NULL.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Please note that this function handles the background segments and certain text segments that the L_MrcSegmentBitmap function handles. In addition, the L_MrcSegmentBitmap function will be removed in the next major release of LEADTOOLS and this function will replace it.

Call this function to segment the bitmap automatically. LEAD will process the bitmap and break it into appropriate picture, grayscale, text and background segments.

Call the L_MrcStartBitmapSegmentation function before using any of the segmentation functions. When the handle to the segmentation is no longer needed, free it by calling the L_MrcStopBitmapSegmentation function.

Required DLLs and Libraries

LTSGM

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

See Also

Functions:

L_MrcStartBitmapSegmentation, L_MrcStopBitmapSegmentation, L_MrcSetSegmentData, L_MrcDeleteSegment, L_MrcCombineSegments, L_MrcEnumSegments, L_MrcSaveSegmentation, L_MrcLoadSegmentation, L_MrcCopySegmentationHandle, L_MrcSegmentBitmap

Topics:

Auto-Segmentation

 

MRC Bitmap Functions: Automatic Segmentation

Example

//The following example loads a bitmap and then performs automatic segmentation using the L_MrcSegmentBitmapExt function.

 

/* pMRCENUMSEGMENTSPROC callback function */
L_INT EXT_CALLBACK EnumAutoSegments (HSEGMENTATION       hSegment, 
                                     const pSEGMENTDATA  pSegment, 
                                     L_INT               nSegId, 
                                     L_VOID L_FAR*       pUserData) 
{
   L_TCHAR szSegmentRect[256]; 
   L_TCHAR szSegmentId[256]; 

   memset(szSegmentRect, 0, 256); 
   memset(szSegmentId, 0, 256); 

   wsprintf(szSegmentId, TEXT("Segment ID %d"), nSegId); 
   wsprintf(szSegmentRect, TEXT("Left = %d, Top = %d, Right = %d, Bottom = %d"), pSegment->rcBitmapSeg.left,  pSegment->rcBitmapSeg.top, pSegment->rcBitmapSeg.right, pSegment->rcBitmapSeg.bottom); 

   MessageBox(NULL, szSegmentRect, szSegmentId, MB_OK); 

   return SUCCESS; 
}

L_INT AutoSegmentation(pBITMAPHANDLE pBitmap) 
{
   HSEGMENTATION     hSegmentation; 
   SEGMENTEXTOPTIONS SegExtOption; 
   L_INT nRet; 
   
   /* Specify the minimum segment width and height*/
   
   SegExtOption.uStructSize            = sizeof(SEGMENTEXTOPTIONS); 
   SegExtOption.uBackGroundThreshold   = 10; 
   SegExtOption.uSegmentQuality        = 50;  
   SegExtOption.uColorThreshold        = 25; 
   SegExtOption.uCleanSize             = 5; 
   SegExtOption.uCombineThreshold      = 75; 
   SegExtOption.uFlags                 = SGM_WITHOUTBKGRND | SGM_FAVOR_TWOBIT; 
   
   /* Start the segmentation process */
   nRet = L_MrcStartBitmapSegmentation (&hSegmentation, pBitmap, RGB(255, 255, 255), RGB(0, 0, 0)); 
   if (nRet != SUCCESS) 
      return nRet; 

   /* do the auto-segmentation*/
   nRet = L_MrcSegmentBitmapExt(hSegmentation, pBitmap, &SegExtOption); 
   if (nRet != SUCCESS) 
      return nRet; 

   L_MrcEnumSegments(hSegmentation, (pMRCENUMSEGMENTSPROC)&EnumAutoSegments, NULL, 0); 

   /* end the segmentation process */
   nRet = L_MrcStopBitmapSegmentation(hSegmentation); 
   if (nRet != SUCCESS) 
      return nRet; 

   return SUCCESS; 
}