L_MrcSegmentBitmap

#include "ltsgm.h"

L_INT EXT_FUNCTION L_MrcSegmentBitmap(hSegment, pBitmap, pMinSeg, pSegOption)

HSEGMENTATION hSegment;

/* segmentation handle */

pBITMAPHANDLE pBitmap;

/* pointer to a bitmap handle */

pMINSEGMENT pMinSeg;

/* pointer to a structure */

SEGMENTATIONOPTIONS pSegOption;

/* pointer to a structure */

Automatically segments the specified bitmap. This function is available 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.

pMinSeg

Pointer to the MINSEGMENT structure that contains the desired minimum width and height for the segments. This cannot be NULL.

pSegOption

Pointer to the SEGMENTATIONOPTIONS structure that controls the auto segmentation process. This cannot be NULL.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Please note that the L_MrcSegmentBitmap function will be removed in Version 15. It is being replaced with the L_MrcSegmentBitmapExt function.

Call this function to segment the bitmap automatically. LEADTOOLS segments the bitmap into blocks nMinWidth wide by nMinHeight long. Blocks with the same characteristics may be combined. Segments are assigned a type according to the number of colors they have (those with a few colors become text segments and those with many colors become picture 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.

The nMinWidth and nMinHeight members of the MINSEGMENT structure must be set before calling this function.

Values less than 10x10 pixels will cause an error.

Use the members of the SEGMENTATIONOPTIONS structure to control the segmentation process. If the L_MrcSegmentBitmap function is called with SEGMENTATIONOPTIONS.uImageType member set to IMAGETYPE_SCANNED, noise is removed from the image before segmenting it. Set the uImageType member to IMAGETYPE_COMPUTERGENERATED if noise does not need to be removed from the image.

It is also possible to use the L_MrcSegmentBitmapExt function to segment a bitmap automatically. When used to perform segmentation that will be saved to a file, the L_MrcSegmentBitmapExt function results in a higher quality file than the L_MrcSegmentBitmap 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_MrcSegmentBitmapExt

Topics:

Auto-Segmentation

 

MRC Bitmap Functions: Automatic Segmentation

Example

Auto-segmentation example

/* 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;
   MINSEGMENT MinSegment;
   SEGMENTATIONOPTIONS SegOpt;
   L_INT nRet;
   
   /* Specify the minimum segment width and height*/
   MinSegment.uStructSize = sizeof(MINSEGMENT);
   MinSegment.nMinWidth = 60;
   MinSegment.nMinHeight = 60;

   SegOpt.uStructSize = sizeof(SEGMENTATIONOPTIONS);
   SegOpt.uSensitivity = 25;
   SegOpt.uCombineFlags = COMBINE_TRY;
   SegOpt.uCombineFactor = 30;
   SegOpt.uImageType = IMAGETYPE_COMPUTERGENERATED;
   
   /* 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_MrcSegmentBitmap(hSegmentation, pBitmap, &MinSegment, &SegOpt);
   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;
}