Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, August 9, 2007 11:36:50 AM(UTC)

MrWayne  
MrWayne

Groups: Registered
Posts: 14


We are using LeadTools 14.5 within a general utility DLL to provide some basic image services such as: getNumberOfPagesInImage() and getImageXResolution() via L_FileInfo().

Recently received images would be better handled by our main software if we could provide services such as despeckling, line removal, and removal of shading within a region.

Could you point me to relevant LeadTools functions. The documentation has served me well in the past if you can show me where to start looking.

Thanks.
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Monday, August 13, 2007 4:09:02 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 356


These functions are available to owners of LEADTOOLS Document Imaging toolkits. Please check the help topics for the L_DespeckleBitmap() and L_LineRemoveBitmap() functions:

About removal of shading within a region, could you explain in detail what exactly you mean by this?

Amin Dodin

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#3 Posted : Friday, August 17, 2007 6:31:17 AM(UTC)

MrWayne  
MrWayne

Groups: Registered
Posts: 14


Removal of shading within a region enhances OCR accuracy. I have attached a portion of one of these images for your review. The attachment is a zipped TIF.
File Attachment(s):
Shaded_Text.zip (22kb) downloaded 20 time(s).
 
#4 Posted : Tuesday, August 21, 2007 12:40:45 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 356


The image you posted is 1-bit black and white. This means the area that appears shaded does not contain real gray shades, but black and white dots that create the appearance of shades.
One way to lose these dots and keep the heavier parts of the image (such as text characters) is to do the following:
1. Convert the image to 8-bit grayscale

2. Blur it to 'melt' the black dots by using the average function with a dimension of 3 for example.

3. Remove the melted shades by using Intensity Detect function with values (110, 255)

4. Convert it back to 1 bit

5. Use the Dot Remove function to further enhance the result.

However, please keep in mind that this image has very poor quality to begin with. If at all possible, it's better to scan such images at a much higher resolution to enhance the OCR accuracy.

Amin Dodin

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#5 Posted : Wednesday, August 22, 2007 7:35:28 AM(UTC)

MrWayne  
MrWayne

Groups: Registered
Posts: 14


I have created a simple application to apply the five steps described above. The code used for Step 5 is shown below. My final output image is not what I expected, however.

When I include the IMAGE_UNCHANGED flag in the DOTREMOVE structure, my output image contains the small dots plus slightly offset rectangles with animated dotted-line borders. When I do not include the IMAGE_UNCHANGED flag, my output image contains the rectangles with animated dotted-line borders.

For development and testing purposes it is nice to see which regions have been identified as dots for removal. What do I need to do actually erase / whiteout / remove the dot rectangles?

*** Code segment follows ***

////////////////////////////////////////////
// Step 5 - Apply Dot Removal
////////////////////////////////////////////
// Delete the 8 bpp BITMAPHANDLE
nRet = L_FreeBitmapRgn( &bmh );

// Load the image
nRet = L_LoadBitmap( (char *)strOutput2.c_str(), &bmh, sizeof(BITMAPHANDLE),
0, ORDER_BGR, NULL, NULL );

// Prepare bitmap region for dot removal
BITMAPHANDLE bmRegion;
memset( &bmRegion, 0, sizeof(BITMAPHANDLE) );
bmRegion.uStructSize = sizeof(BITMAPHANDLE);

// Prepare DOTREMOVE structure
DOTREMOVE dr;
dr.uStructSize = sizeof( DOTREMOVE );
dr.iMinDotWidth = 1;
dr.iMinDotHeight = 1;
dr.iMaxDotWidth = 3;
dr.iMaxDotHeight = 3;
dr.uFlags =
DOT_USE_SIZE | // use dot height and dot width settings
DOT_SINGLE_REGION | // removed dots are added to internal single region
DOT_LEAD_REGION; // bmRegion is updated with shallow copy of removed dots region
// DOT_LEAD_REGION | // bmRegion is updated with shallow copy of removed dots region
// DOT_IMAGE_UNCHANGED; // the original image is unchanged
dr.pBitmapRegion = &bmRegion;
dr.uBitmapStructSize = sizeof(BITMAPHANDLE);

// Call dot removal
nRet = L_DotRemoveBitmap( &bmh, &dr, NULL, NULL );

// Update the bitmap
if (nRet == SUCCESS)
{
RECT rectRgn;

// Delete the existing region
nRet = L_FreeBitmapRgn( &bmh );

// Copy new region into existing region
nRet = L_GetBitmapRgnBounds( dr.pBitmapRegion, NULL, &rectRgn );
if (!IsRectEmpty( &rectRgn ))
{
nRet = L_CopyBitmapHandle( &bmh, dr.pBitmapRegion, sizeof(BITMAPHANDLE) );
}
}

// Save the result
strOutput = createSteppedFileName( strImageFileName, 5 );
nRet = L_SaveBitmap( (char *)strOutput.c_str(), &bmh, nType, nBitsPerPixel, 0, NULL );

*** End of code segment ***
 
#6 Posted : Wednesday, August 22, 2007 9:59:14 AM(UTC)

MrWayne  
MrWayne

Groups: Registered
Posts: 14


I found the solution. Instead of calling L_CopyBitmapHandle() inside the last if block, call L_CombineBitmap()

*** EXAMPLE ***

nRet = L_GetBitmapRgnBounds( dr.pBitmapRegion, NULL, &rectRgn );
if (!IsRectEmpty( &rectRgn ))
{
nRet = L_CombineBitmap( &bmh, 0, 0, BITMAPWIDTH( &bmh ), BITMAPHEIGHT( &bmh ), dr.pBitmapRegion, 0, 0, CB_OP_XOR | CB_DST_0 );
}

*** END EXAMPLE ***
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.179 seconds.