Cleaning Up Color Images with LEADTOOLS Document Imaging

Posted on 2016-10-07 Greg

One of the most foundational features in document imaging is image cleanup (also called preprocessing). When paper documents are scanned to digital form there are almost always imperfections. The paper can be at an angle, hole punches leave large black dots, folded paper introduces lines, and at the very least dust speckles litter small, dark dots throughout the image. All of these can have an adverse trickle-down effect on many other algorithms such as OCR, Forms, Barcode, Compression and more.

There is one caveat with most document imaging libraries: the document images must be black and white. While technically true for LEADTOOLS as well, it's not a limitation whatsoever. Each of the LEADTOOLS document cleanup functions return information on what it has done. For example, you can get the deskew angle, rectangle to crop, or region to fill and then apply those same operations on a color image:


// First make a copy of the image
using (RasterImage image = viewer.Image.Clone())
{
   // If the image is not 1bpp black and white, convert it
   if (image.BitsPerPixel != 1)
   {
      AutoBinarizeCommand autoBin = new AutoBinarizeCommand();
      autoBin.Flags = AutoBinarizeCommandFlags.DontUsePreProcessing;
      autoBin.Run(image);
      ColorResolutionCommand colorRes = new ColorResolutionCommand();
      colorRes.BitsPerPixel = 1;
      colorRes.Run(image);
   }

   // Process the 1bpp copy
   DeskewCommand deskewCom = new DeskewCommand();
   deskewCom.Flags = DeskewCommandFlags.ReturnAngleOnly;
   deskewCom.Run(image);

   // Apply the same transformation on the original color image using 
   // the data from the 1bpp cleanup function
   RotateCommand rotateCom = new RotateCommand();
   rotateCom.Flags = RotateCommandFlags.Resample;
   rotateCom.FillColor = viewer.Image.GetPixelColor(0, 0);
   rotateCom.Angle = deskewCom.Angle;
   rotateCom.Run(viewer.Image);
}

To see more and play with it on your own images, you can download the full example from the original forum post.

LEADTOOLS Blog

LEADTOOLS Powered by Apryse,the Market Leading PDF SDK,All Rights Reserved