LBitmap::InvertedText

#include "ltwrappr.h"

virtual L_INT LBitmap::InvertedText(pInvertedText)

LPINVERTEDTEXT pInvertedText;

/* pointer to a structure */

Finds and inverts areas of inverted text in a 1-bit black and white image. This function is available in the Document/Medical Toolkits.

Parameter

Description

pInvertedText

Pointer to the INVERTEDTEXT structure that LEADTOOLS uses to find and correct inverted text.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function finds and inverts areas of inverted text that are common in scanned text documents.

Below is an example of inverted text often found in scanned images:

image\Invert1.gif

Modifying the area of inverted text yields:

image\Invert2.gif

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

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::InvertedTextCallback, LBitmap::Smooth, LBitmap::LineRemove, LBitmap::BorderRemove, LBitmap::DotRemove, LBitmap::HolePunchRemove

Topics:

Cleaning Up 1-Bit Images

Example

//This example finds all inverted text regions greater than 5 inches in width and 1/2 inch in height
// and inverts it so that it appears normal
//The derived class LMyBitmap is used to override the InvertedTextCallBack function 
//The callback member function is used to display additional information about the inverted text regions
//The callback member function does NOT receive a Windows region
//A LEAD region is updated by the function to show all of the changes.

void CCleanv12Dlg::OnButtonInvertedtext() 
{
   L_INT32    nRet;
   BITMAPHANDLE   BitmapRegion;
   INVERTEDTEXT   it;
   it.uStructSize = sizeof(INVERTEDTEXT);
   memset(&BitmapRegion, 0, sizeof(BITMAPHANDLE));

   it.iSize  = sizeof(INVERTEDTEXT);

   //Units are in thousands of inches
   it.iMinInvertWidth   = 5000;
   it.iMinInvertHeight  = 500;
   it.iMinBlackPercent  = 70;
   it.iMaxBlackPercent  = 95;
   it.pBitmapRegion     = &BitmapRegion;
   it.uBitmapStructSize = sizeof(BitmapRegion);
   it.uFlags    = INVERTEDTEXT_SINGLE_REGION | INVERTEDTEXT_LEAD_REGION | INVERTEDTEXT_USE_DPI;
      
   nRet = m_Bitmap.InvertedText(&it);
   
   if (nRet == SUCCESS)
   {
      //Delete the existing region
      LBitmapRgn Region(&m_Bitmap);  
      if(Region.BitmapHasRgn())
      {
         Region.Free();
      }
      
      m_Bitmap.SetHandle(it.pBitmapRegion, FALSE); 
      Invalidate();   
   }
}

L_INT LMyBitmap::InvertedTextCallBack(
                                      HRGN          hRgn, 
                                      PRECT         pBoundingRect, 
                                      L_INT32       iWhiteCount, 
                                      L_INT32       iBlackCount
                                      )
{
   CString  strMsg;
   
   //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);
   return SUCCESS_REMOVE;
}