LBitmap::DotRemove

#include "ltwrappr.h"

virtual L_INT LBitmap::DotRemove(pDotRemove)

LPDOTREMOVE pDotRemove;

/* pointer to a structure */

Finds and removes dots and specks of various sizes. This function is available in the Document/Medical Toolkits.

Parameter

Description

pDotRemove

Pointer to the DOTREMOVE structure that LEADTOOLS uses to remove dots.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function finds and removes dots, specks, and blobs of various sizes in 1-bit documents. The dots, specks, and blobs may or may not be all black.

This function works only on 1-bit black and white images.

If a region is selected, only the selected region will be changed by this function. If no region is selected, the whole image will be processed.

The behavior of this function can be modified by overriding LBitmap::DotRemoveCallback.

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.

Required DLLs and Libraries

LTIMG

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:

LBitmap::DotRemoveCallback, LBitmap::Smooth, LBitmap::LineRemove, LBitmap::InvertedText, LBitmap::BorderRemove, LBitmap::HolePunchRemove

Topics:

Cleaning Up 1-Bit Images

Example

//This example updates a region with all 1x1 to 3x3 specks that are solid black
//If a speck has any white pixels, it is NOT added to the region
//The call is configured to update a single LEAD region corresponding to all changes
//The image itself is unchanged
//The derived class LMyBitmap is used to override the DotRemoveCallBack function 
//The callback member function is used to display information about each speck that is removed
//The callback member function does NOT receive a Windows region

void CCleanv12Dlg::OnButtonDots() 
{
   L_INT32        nRet;
   BITMAPHANDLE   BitmapRegion;
   DOTREMOVE      dr;
    dr.uStructSize = sizeof(DOTREMOVE);
   
   memset(&BitmapRegion, 0, sizeof(BITMAPHANDLE));
   
   dr.uStructSize    = sizeof(DOTREMOVE);

   dr.uBitmapStructSize = sizeof(BITMAPHANDLE);
   dr.iMinDotWidth   = 1;
   dr.iMinDotHeight  = 1;
   dr.iMaxDotWidth   = 3;
   dr.iMaxDotHeight  = 3;
   dr.uFlags         = DOT_USE_SIZE | DOT_SINGLE_REGION | DOT_LEAD_REGION | DOT_IMAGE_UNCHANGED;
   dr.pBitmapRegion  = &BitmapRegion;
   dr.uBitmapStructSize = sizeof(BitmapRegion);
   nRet = m_Bitmap.DotRemove(&dr);
   
   if (nRet == SUCCESS)
   {
      //Delete the existing region
      LBitmapRgn Region(&m_Bitmap);  
      if(Region.BitmapHasRgn())
      {
         Region.Free();
      }
      
      m_Bitmap.SetHandle(dr.pBitmapRegion, FALSE); 
      Invalidate();   
   }   
}

L_INT LMyBitmap::DotRemoveCallBack(
                                   HRGN          hRgn, 
                                   PRECT         pBoundingRect, 
                                   L_INT32       iWhiteCount, 
                                   L_INT32       iBlackCount
                                   )
{
   CString  strMsg;
   L_INT32 nRet;
   
   //Note: no hRgn to delete because it was not requested
   strMsg.Format(
      TEXT("Size[%dx%d]\tBounds[%d,%d][%d,%d]\tWhiteCount[%d]\tBlackCount[%d]\n"),
      pBoundingRect->right - pBoundingRect->left,
      pBoundingRect->bottom - pBoundingRect->top,
      pBoundingRect->left,
      pBoundingRect->top,
      pBoundingRect->right,
      pBoundingRect->bottom,
      iWhiteCount,
      iBlackCount);
   OutputDebugString(strMsg);
   
   //Do not remove the speck if it contains any white pixels
   if (iWhiteCount > 0) 
   {
      nRet = SUCCESS_NOREMOVE;
   }
   else 
   {
      nRet = SUCCESS_REMOVE;
   }
   return nRet; 
}