Finds and inverts areas of inverted text in a 1-bit black and white image.
#include "ltwrappr.h"
virtual L_INT LBitmap::InvertedText(pInvertedText, uFlags = 0)
Pointer to the INVERTEDTEXT structure that LEADTOOLS uses to find and correct inverted text.
Reserved for future use. Must be 0.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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:
Modifying the area of inverted text yields:
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.
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.
Inverted Text Function - Before
Inverted Text Function - After
View additional platform support for this Inverted Text function.
Win32, x64.
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.
class LInvertedTextBitmap : public LBitmap
{
public:
LInvertedTextBitmap();
~LInvertedTextBitmap();
virtual L_INT LInvertedTextBitmap::InvertedTextCallBack(HRGN hRgn,
PRECT pBoundingRect,
L_INT32 iWhiteCount,
L_INT32 iBlackCount
);
};
LInvertedTextBitmap::LInvertedTextBitmap()
{
}
LInvertedTextBitmap::~LInvertedTextBitmap()
{
}
L_INT LInvertedTextBitmap::InvertedTextCallBack(HRGN hRgn,
PRECT pBoundingRect,
L_INT32 iWhiteCount,
L_INT32 iBlackCount
)
{
UNREFERENCED_PARAMETER(hRgn);
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;
}
L_INT LBitmap__InvertedTextExample(LBitmapWindow *pBitmapWindow)
{
L_INT32 nRet;
BITMAPHANDLE BitmapRegion;
INVERTEDTEXT it;
it.uStructSize = sizeof(INVERTEDTEXT);
memset(&BitmapRegion, 0, sizeof(BITMAPHANDLE));
it.uStructSize = 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 = pBitmapWindow->InvertedText(&it);
if (nRet == SUCCESS)
{
//Delete the existing region
LBitmapRgn Region(pBitmapWindow);
if(Region.BitmapHasRgn())
{
Region.Free();
}
pBitmapWindow->SetHandle(it.pBitmapRegion, FALSE);
}
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document