LBitmap::BorderRemove

#include "ltwrappr.h"

virtual L_INT LBitmap::BorderRemove(pBorderRemove, uFlags = 0)

pBORDERREMOVE pBorderRemove;

/* pointer to a structure */

L_UINT32 uFlags;

/* flags */

Removes the black borders in a 1-bit black and white image.

Parameter

Description

pBorderRemove

Pointer to the BORDERREMOVE structure that LEADTOOLS uses to remove borders.

uFlags

Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function removes borders that commonly appear in scanned text documents. Any or all of the four borders can be detected and removed.

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::BorderRemoveCallback.

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 code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

LTIMGCOR

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::BorderRemoveCallback, LBitmap::Smooth, LBitmap::LineRemove, LBitmap::InvertedText, LBitmap::DotRemove, LBitmap::HolePunchRemove, LBitmap::AutoBinarize, LBitmap::DynamicBinary, LBitmap::AutoBinary, Class Members

Topics:

Cleaning Up 1-Bit Images

Example

//This example updates a Windows region with the removed borders of a bitmap

//The derived class LMyBitmap is used to override the BorderRemoveCallBack function

//myBitmap is an object of class LMyBitmap.

//For the example, Windows regions are received by the BorderRemoveCallBack function and combined.

//In practice it would be easier and faster to just update a LEAD region with the changes

//The borders are removed from the image.

class LBorderRemoveBitmap : public LBitmap
{
public:
   LBorderRemoveBitmap();
   ~LBorderRemoveBitmap();
   L_INT BorderRemoveCallBack(HRGN          hRgn, 
                              L_UINT32      uBorderToRemove, 
                              PRECT         pBoundingRect
                              );
};
LBorderRemoveBitmap::LBorderRemoveBitmap()
{
}
LBorderRemoveBitmap::~LBorderRemoveBitmap()
{
}
L_INT LBorderRemoveBitmap::BorderRemoveCallBack(HRGN          hRgn, 
                                                L_UINT32      uBorderToRemove, 
                                                PRECT         pBoundingRect
                                                )
{
     CString  strMsg;
     CString  strBorder;
     HRGN hRgnAll = NULL;
     ::CombineRgn( hRgnAll, hRgnAll, hRgn,  RGN_OR);
     DeleteObject(hRgn);
     switch (uBorderToRemove)
     {
     case BORDER_TOP:
        strBorder = TEXT("Top");
        break;
     case BORDER_LEFT:
        strBorder = TEXT("Left");
        break;
     case BORDER_RIGHT:
        strBorder = TEXT("Right");
        break;
     case BORDER_BOTTOM:
        strBorder = TEXT("Bottom");
        break;
     }
     strMsg.Format(
        TEXT("Border[%s]\tBounds[%d,%d][%d,%d]\n"),
        strBorder,
        pBoundingRect->left,
        pBoundingRect->top,
        pBoundingRect->right,
        pBoundingRect->bottom
        );
     OutputDebugString(strMsg);
     return SUCCESS_REMOVE; 
}
L_INT LBitmap__BorderRemoveExample(LBitmapWindow *pBitmapWindow)
{
  L_INT32        nRet;
  BORDERREMOVE   br;
  br.uStructSize = sizeof(BORDERREMOVE);
  //Create a NULL region
  RECT rect ={0, 0, 0, 0};
  pBitmapWindow->Region()->SetRgnRect(&rect);
  br.uStructSize             = sizeof(DOTREMOVE);
  br.uBitmapStructSize = sizeof(BITMAPHANDLE);
  br.iBorderPercent    = 20;
  br.iVariance         = 2;
  br.iWhiteNoiseLength = 5;
  br.uBorderToRemove   = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT;
  br.uFlags            = BORDER_CALLBACK_REGION | BORDER_USE_VARIANCE;
  nRet = pBitmapWindow->BorderRemove(&br);
  if (nRet == SUCCESS)
  {
     //Delete the existing region
     LBitmapRgn Region(pBitmapWindow);
     if(Region.BitmapHasRgn())
     {
        Region.Free();
     }
     Region.SetRgnCombineMode(L_RGN_SET) ;
     Region.SetRgnHandle(pBitmapWindow->Region()->GetRgnHandle());
  }
  return SUCCESS;
}