LBitmap::BorderRemove

#include "ltwrappr.h"

virtual L_INT LBitmap::BorderRemove(pBorderRemove)

LPBORDERREMOVE pBorderRemove;

/* pointer to a structure */

Removes the black borders in a 1-bit black and white image. This function is available in the Document/Medical Toolkits.

Parameter

Description

pBorderRemove

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

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.

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::BorderRemoveCallback, LBitmap::Smooth, LBitmap::LineRemove, LBitmap::InvertedText, LBitmap::DotRemove, LBitmap::HolePunchRemove

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.

void CCleanv12Dlg::OnButtonBorder() 
{
   L_INT32        nRet;
   BORDERREMOVE   br;
   br.uStructSize = sizeof(BORDERREMOVE);
   //Create a NULL region
   RECT rect ={0, 0, 0, 0};

   m_Bitmap.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 = m_Bitmap.BorderRemove(&br);
   
   if (nRet == SUCCESS)
   {
      //Delete the existing region
      LBitmapRgn Region(&m_Bitmap);  
      if(Region.BitmapHasRgn())
      {
         Region.Free();
      }
      
      Region.SetRgnCombineMode(L_RGN_SET) ;
      Region.SetRgnHandle(Bitmap.Region()->GetRgnHandle());
   }
}

L_INT LMyBitmap::BorderRemoveCallBack(
                                      HRGN          hRgn, 
                                      L_UINT32      uBorderToRemove, 
                                      PRECT         pBoundingRect
                                      )
{
   CString  strMsg;
   CString  strBorder;
   
   ::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; 
}