With any type of recognition you will get out of it what you put it, meaning that the better quality the input the better the results. It is understandable that input quality cannot be assured 100% for example with scanned documents or faxes. To help with this LEADTOOLS offers a variety of clean up and processing commands. The following is a checklist of sorts that I find useful when dealing with low success recognition.
Input DPITypically the recommended DPI is 200-300 for best results.
You can handle this on Load specifying load options for the RasterCodecs class.
RasterizeDocument and
LoadCode://if loading a document format
codecs.Options.RasterizeDocument.Load.XResolution = 300;
codecs.Options.RasterizeDocument.Load.YResolution = 300;
//loading image with no DPI information
codecs.Options.Load.XResolution = 300;
codecs.Options.Load.YResolution = 300;
Most images already have DPI information and in order to change this you will need to do some resizing:
Code:static void ResizeDPI(RasterImage image, int xResolution, int yResolution)
{
if (image.XResolution == xResolution && image.YResolution == yResolution)
return;
double width = (image.Width / image.XResolution) * xResolution;
double height = (image.Height / image.YResolution) * yResolution;
SizeCommand sizeCommand = new SizeCommand((int)width, (int)height, RasterSizeFlags.Bicubic);
sizeCommand.Run(image);
image.XResolution = xResolution;
image.YResolution = yResolution;
}
Fix skewed imagesEspecially when the input is a scanned image the input file may be skewed. To correct this you can run our DeskewCommand:
https://www.leadtools.com/help/sdk/dh/po/deskewcommand.htmlYou can see this command in action here:
https://www.leadtools.com/help/sdk/image-processing-functions/deskew.htmlCode:DeskewCommand deskew = new DeskewCommand();
deskew.Run(image);
In this example image being the RasterImage instance that contains your input.
Black and White for best resultsYou can levaerage our AutoBinarize command to automatically create a black and white image using your input file. Most recognition works best on B/W images.
https://www.leadtools.com/help/sdk/dh/po/autobinarizecommand.htmlCode:AutoBinarizeCommand autoBinarize = new AutoBinarizeCommand();
autoBinarize.Run(image);
You can also use DynamicBinaryCommand to achieve this with more control:
https://www.leadtools.com/help/sdk/dh/pc/dynamicbinarycommand.htmlNoise ReductionLEADTOOLS offers a number of commands to deal with noisy images, these commands along with the binarization routines mentioned above will be the most helpful in improving recognition rates. For this you can use the following:
Minimun Command, dialte dark objects in the image:
https://www.leadtools.com/help/sdk/dh/po/minimumcommand.htmlMedianCommand, changes the pixel color to that of the median value of the pixel in its neighborhood:
https://www.leadtools.com/help/sdk/dh/po/mediancommand.htmlMaximunCommand, erodes dark objects in the image:
https://www.leadtools.com/help/sdk/dh/po/maximumcommand.htmlDespekleCommand, removes speckles/noise from the image. Great for scanned and faxed files.
https://www.leadtools.com/help/sdk/dh/po/despecklecommand.htmlEdited by moderator Wednesday, December 27, 2023 3:31:24 PM(UTC)
| Reason: Updated
Roberto Rodriguez
Developer Support Engineer
LEAD Technologies, Inc.