Leadtools.ImageProcessing.Core Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
InvertedPageCommand Class
See Also  Members   Example 
Leadtools.ImageProcessing.Core Namespace : InvertedPageCommand Class



Checks and auto-corrects an inverted image.

Syntax

Visual Basic (Declaration) 
Public Class InvertedPageCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As InvertedPageCommand
C# 
public class InvertedPageCommand : RasterCommand, IRasterCommand  
C++/CLI 
public ref class InvertedPageCommand : public RasterCommand, IRasterCommand  

Example

This example will show how to use the InvertedPageCommand class to check and auto-correct inverted images.

Visual BasicCopy Code
Public Sub InvertedPageCommandExample()
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()

   ' Get an image
   Dim tifFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\ocr1.tif"
   Dim invertedImageFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\ocr1_Inverted.tif"
   Dim nonInvertedImageFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\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()
   RasterCodecs.Shutdown()
End Sub
C#Copy Code
public void InvertedPageCommandExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Get an image 
   string tifFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\ocr1.tif"; 
   string invertedImageFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\ocr1_Inverted.tif"; 
   string nonInvertedImageFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\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(); 
   RasterCodecs.Shutdown(); 
}

Remarks

An inverted 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.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Core.InvertedPageCommand

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also