LSegment::MrcSegmentBitmap

#include "ltwrappr.h"

L_INT LSegment::MrcSegmentBitmap(pBitmap, pMinSeg, uSegFactor)

LBitmapBase * pBitmap;

/* pointer to an LBitmapBase object */

pMINSEGMENT pMinSeg;

/* pointer to a structure */

pSEGMENTATIONOPTIONS pSegOpt;

/* pointer to a structure */

Automatically segments the specified bitmap. This function is available in the (Document/Medical) toolkits.

Parameter

Description

pBitmap

Pointer to an LBitmapBase object that references the bitmap to be segmented.

pMinSeg

Pointer to the MINSEGMENT structure that contains the desired minimum width and height for the segments.

pSegOpt

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 LSegment::MrcSegmentBitmap function will be removed in Version 15. It is being replaced with the LSegment::MrcSegmentBitmapExt function.

Call this function to segment the bitmap automatically. LEADTOOLS segments the bitmap into blocks pMinSeg->nMinWidth wide by pMinSeg->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 LSegment::MrcStartBitmapSegmentation function before using any of the segmentation functions. When the LSegment class object is no longer needed, free it by calling the LSegment::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 LSegment::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.

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

Elements:

LSegment::MrcStartBitmapSegmentation, LSegment::MrcStopBitmapSegmentation, LSegment::MrcEnumSegments, LSegment::MrcSetSegmentData, LSegment::MrcDeleteSegment, Class Members

Topics:

General Segmentation

 

Auto-Segmentation

Example

The following example illustrates the use of LSegment::MrcSegmentBitmap to perform auto segmentation.

// Create a new class derived from LSegment and
// override LSegment::MrcEnumSegmentsCallBack
class LUserSeg : public Lsegment
{
   virtual L_INT MrcEnumSegmentsCallBack(const pSEGMENTDATA pSegment, 
                                         L_INT nSegId)
   {
       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_VOID AutoSegmentBitmap(LBitmapBase & Bitmap)
{
   LUserSeg Segment;
   MINSEGMENT ms;
   SEGMENTATIONOPTIONS SegOpt;
   
   // Specify the minimum segment width and height
   ms.uStructSize = sizeof(MINSEGMENT);
   ms.nMinWidth = 60;
   ms.nMinHeight = 60;

   // Specify the segmentation options
   SegOpt.uStructSize = sizeof(SEGMENTATIONOPTIONS);
   SegOpt.uSensitivity = 25;
   SegOpt.uCombineFlags = COMBINE_TRY;
   SegOpt.uCombineFactor = 30;
   SegOpt.uImageType = IMAGETYPE_COMPUTERGENERATED;

   // Initialize the segmentation process
   Segment.MrcStartBitmapSegmentation(&Bitmap,
                                      RGB(255, 255, 255), 
                                      RGB(0, 0, 0));
   // Perform the auto segmentation process
   Segment.MrcSegmentBitmap(&Bitmap, &ms, &SegOpt);

   // Enumerate the resulted segments
   Segment.MrcEnumSegments(0);

   // Clean up
   Segment.MrcStopBitmapSegmentation ();
}