LEADTOOLS Image Processing (Leadtools.ImageProcessing.Core assembly)
LEAD Technologies, Inc

InvertedPageCommand Class

Example 





Members 
Checks and auto-corrects an inverted image. .NET support WinRT support Silverlight support
Object Model
InvertedPageCommand Class
Syntax
'Declaration
 
Public Class InvertedPageCommand 
   Inherits Leadtools.ImageProcessing.RasterCommand
   Implements Leadtools.ImageProcessing.IRasterCommand 
'Usage
 
Dim instance As InvertedPageCommand
public sealed class InvertedPageCommand : Leadtools.ImageProcessing.IRasterCommand  
function Leadtools.ImageProcessing.Core.InvertedPageCommand()
Remarks

An inverted Leadtools.RasterImage is an image that has text or other objects in high contrast color on a low contrast background, for example white text on black background. This command can check whether an image is inverted as well as auto-correct it.

This command can only detect an entire image. To search for and correct specific inverted areas or regions in an image, use the InvertedTextCommand.

A common source of inverted images are black and white images saved with a non-standard palette by some applications.

This command does not support signed data images.

For more information, refer to Cleaning Up 1-Bit Images.

In Silverlight and Windows Phone versions of LEADTOOLS, this image processing command will fail if the image data for the RasterImage object is stored internally using a Silverlight WriteableBitmap object. For more information, refer to Image Processing Command Limitations in Silverlight.

Example
 
Public Sub InvertedPageCommandExample()
   Dim codecs As New RasterCodecs()

   ' Get an image
   Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ocr1.tif")
   Dim invertedImageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_Inverted.tif")
   Dim nonInvertedImageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_NonInverted.tif")

   Dim image As RasterImage = codecs.Load(tifFileName)

   ' The images should be non-inverted at the beginning, check
   Dim invertedPage As New InvertedPageCommand(InvertedPageCommandFlags.NoProcess)
   invertedPage.Run(image)
   Console.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted)

   ' Invert the image
   Dim invert As New InvertCommand()
   invert.Run(image)

   codecs.Save(image, invertedImageFileName, image.OriginalFormat, image.BitsPerPixel)

   ' Check again
   invertedPage.Run(image)
   Console.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted)

   ' Now run the command to un-invert the image
   invertedPage.Flags = InvertedPageCommandFlags.Process
   invertedPage.Run(image)

   ' Now check the image again
   invertedPage.Flags = InvertedPageCommandFlags.NoProcess
   invertedPage.Run(image)
   Console.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted)
   codecs.Save(image, nonInvertedImageFileName, image.OriginalFormat, image.BitsPerPixel)

   image.Dispose()

   codecs.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void InvertedPageCommandExample()
   {
      RasterCodecs codecs = new RasterCodecs();

      // Get an image
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "ocr1.tif");
      string invertedImageFileName = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_Inverted.tif");
      string nonInvertedImageFileName = Path.Combine(LEAD_VARS.ImagesDir, "ocr1_NonInverted.tif");

      RasterImage image = codecs.Load(tifFileName);

      // The images should be non-inverted at the beginning, check
      InvertedPageCommand invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.NoProcess);
      invertedPage.Run(image);
      Console.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted);

      // Invert the image
      InvertCommand invert = new InvertCommand();
      invert.Run(image);

      codecs.Save(image, invertedImageFileName, image.OriginalFormat, image.BitsPerPixel);

      // Check again
      invertedPage.Run(image);
      Console.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted);

      // Now run the command to un-invert the image
      invertedPage.Flags = InvertedPageCommandFlags.Process;
      invertedPage.Run(image);

      // Now check the image again
      invertedPage.Flags = InvertedPageCommandFlags.NoProcess;
      invertedPage.Run(image);
      Console.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted);
      codecs.Save(image, nonInvertedImageFileName, image.OriginalFormat, image.BitsPerPixel);

      image.Dispose();

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
function InvertedPageCommandExample()
{
   var codecs = new Leadtools.Codecs.RasterCodecs();
   var invertedPage;
   var workingImage;

   // Load the image
   var srcFileName = "Assets\\ocr1.tif";
   return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
      return codecs.loadAsync(Leadtools.LeadStreamFactory.create(loadFile));
   }).then(function (image) {
      with (Leadtools.ImageProcessing.Core)
      {
         // The images should be non-inverted at the beginning, check
         invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.noProcess);
         invertedPage.run(image);
         console.error("Original image, inverted = {0}", invertedPage.isInverted);
      }

      // Invert the image
      var invert = new Leadtools.ImageProcessing.Color.InvertCommand();
      invert.run(image);

      workingImage = image;

      var destFileName = "ocr1_Inverted.tif";
      return Tools.AppLocalFolder().createFileAsync(destFileName)
   }).then(function (saveFile) {
      return codecs.saveAsync(workingImage, Leadtools.LeadStreamFactory.create(saveFile), workingImage.originalFormat, workingImage.bitsPerPixel)
   }).then(function () {

      // Check again
      invertedPage.run(workingImage);
      console.error("After running InvertCommand, inverted = {0}", invertedPage.isInverted);

      // Now run the command to un-invert the image
      with (Leadtools.ImageProcessing.Core)
      {
         invertedPage.flags = InvertedPageCommandFlags.process;
         invertedPage.run(workingImage);

         // Now check the image again
         invertedPage.flags = InvertedPageCommandFlags.noProcess;
         invertedPage.run(workingImage);
      }

      console.error("After running InvertedPageCommand, inverted = {0}", invertedPage.isInverted);
      destFileName = "ocr1_NonInverted.tif";
      return Tools.AppLocalFolder().createFileAsync(destFileName);
   }).then(function (saveFile) {
      return codecs.saveAsync(workingImage, Leadtools.LeadStreamFactory.create(saveFile), workingImage.originalFormat, workingImage.bitsPerPixel);
   });
}
[TestMethod]
public async Task InvertedPageCommandExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // Load the image
   string srcFileName = @"Assets\ocr1.tif";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // The images should be non-inverted at the beginning, check
   InvertedPageCommand invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.NoProcess);
   invertedPage.Run(image);
   Debug.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted);

   // Invert the image
   InvertCommand invert = new InvertCommand();
   invert.Run(image);
   string destFileName = @"ocr1_Inverted.tif";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), image.OriginalFormat, image.BitsPerPixel);

   // Check again
   invertedPage.Run(image);
   Debug.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted);

   // Now run the command to un-invert the image
   invertedPage.Flags = InvertedPageCommandFlags.Process;
   invertedPage.Run(image);

   // Now check the image again
   invertedPage.Flags = InvertedPageCommandFlags.NoProcess;
   invertedPage.Run(image);
   Debug.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted);
   destFileName = @"ocr1_NonInverted.tif";
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), image.OriginalFormat, image.BitsPerPixel);

   image.Dispose();

   codecs.Dispose();
}
public void InvertedPageCommandExample(RasterImage image, Stream outStream1, Stream outStream2)
{
   // The images should be non-inverted at the beginning, check
   InvertedPageCommand invertedPage = new InvertedPageCommand(InvertedPageCommandFlags.NoProcess);
   invertedPage.Run(image);
   Debug.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted);
   // Invert the image
   InvertCommand invert = new InvertCommand();
   invert.Run(image);

   RasterCodecs codecs = new RasterCodecs();
   // save image to "ocr1_Inverted.tif";
   codecs.Save(image, outStream1, image.OriginalFormat, image.BitsPerPixel);

   // Check again
   invertedPage.Run(image);
   Debug.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted);

   // Now run the command to un-invert the image
   invertedPage.Flags = InvertedPageCommandFlags.Process;
   invertedPage.Run(image);

   // Now check the image again
   invertedPage.Flags = InvertedPageCommandFlags.NoProcess;
   invertedPage.Run(image);
   Debug.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted);

   // save result image to "ocr1_NonInverted.tif"
   codecs.Save(image, outStream2, RasterImageFormat.CcittGroup4, 1);

   image.Dispose();
}
Public Sub InvertedPageCommandExample(ByVal image As RasterImage, ByVal outStream1 As Stream, ByVal outStream2 As Stream)
   ' The images should be non-inverted at the beginning, check
   Dim invertedPage As InvertedPageCommand = New InvertedPageCommand(InvertedPageCommandFlags.NoProcess)
   invertedPage.Run(image)
   Debug.WriteLine("Original image, inverted = {0}", invertedPage.IsInverted)
   ' Invert the image
   Dim invert As InvertCommand = New InvertCommand()
   invert.Run(image)

   Dim codecs As RasterCodecs = New RasterCodecs()
   ' save image to "ocr1_Inverted.tif";
   codecs.Save(image, outStream1, image.OriginalFormat, image.BitsPerPixel)

   ' Check again
   invertedPage.Run(image)
   Debug.WriteLine("After running InvertCommand, inverted = {0}", invertedPage.IsInverted)

   ' Now run the command to un-invert the image
   invertedPage.Flags = InvertedPageCommandFlags.Process
   invertedPage.Run(image)

   ' Now check the image again
   invertedPage.Flags = InvertedPageCommandFlags.NoProcess
   invertedPage.Run(image)
   Debug.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPage.IsInverted)

   ' save result image to "ocr1_NonInverted.tif"
   codecs.Save(image, outStream2, RasterImageFormat.CcittGroup4, 1)

   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

InvertedPageCommand Members
Leadtools.ImageProcessing.Core Namespace
Cleaning Up 1-Bit Images
SmoothCommand Class
BorderRemoveCommand Class
LineRemoveCommand Class
InvertedTextCommand Class
HighQualityRotateCommand Class
DotRemoveCommand Class
HolePunchRemoveCommand Class
HighQualityRotateCommand Class
MinimumCommand Class
MaximumCommand Class
Leadtools.ImageProcessing.Effects.RegionHolesRemovalCommand

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.