LEADTOOLS WCF Image Processing (Leadtools.Services.ImageProcessing.ServiceContracts assembly)
LEAD Technologies, Inc

InvertedPage Method

Example 





A System.Runtime.Serialization.DataContractAttribute containing the data that will be used in this InvertedPage operation.
Checks and auto-corrects an inverted image.
Syntax
[OperationContractAttribute("InvertedPage")]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
InvertedPageResponse InvertedPage( 
   InvertedPageRequest request
)
'Declaration
 
<OperationContractAttribute("InvertedPage")>
<FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=False)>
Function InvertedPage( _
   ByVal request As InvertedPageRequest _
) As InvertedPageResponse
'Usage
 
Dim instance As IDocumentProcessingService
Dim request As InvertedPageRequest
Dim value As InvertedPageResponse
 
value = instance.InvertedPage(request)
[OperationContractAttribute("InvertedPage")]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
InvertedPageResponse InvertedPage( 
   InvertedPageRequest request
)
OperationContractAttribute("InvertedPage")
FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=)
function Leadtools.Services.ImageProcessing.ServiceContracts.IDocumentProcessingService.InvertedPage( 
   request 
)
[OperationContractAttribute("InvertedPage")]
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
InvertedPageResponse^ InvertedPage( 
   InvertedPageRequest^ request
) 

Parameters

request
A System.Runtime.Serialization.DataContractAttribute containing the data that will be used in this InvertedPage operation.

Return Value

A System.Runtime.Serialization.DataContractAttribute containing the modified image resulting from the InvertedPage operation.
Remarks

An inverted image 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 operation can check if an image is inverted as well as auto-correct.

This operation can only detect an entire image, to search for and correct specific inverted areas or regions in an image, use InvertedText.

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

This operation does not support signed data images.

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

Example
 
Public Sub InvertedPageExample()
      ' 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 documentProcessingClient As DocumentProcessingServiceClient = New DocumentProcessingServiceClient()

      Dim sourceBinaryData As RawBinaryData = New RawBinaryData()
      sourceBinaryData.Data = File.ReadAllBytes(tifFileName)

      Dim convertOptions As RasterConvertOptions = New RasterConvertOptions()

      convertOptions.Source = sourceBinaryData
      convertOptions.Destination = Nothing
      convertOptions.Format = RasterImageFormat.Tif
      convertOptions.FirstPage = 1
      convertOptions.LastPage = 1
      convertOptions.BitsPerPixel = 1
      convertOptions.QualityFactor = 2

      Dim invertedPageRequest As InvertedPageRequest = New InvertedPageRequest()
      invertedPageRequest.Flags = InvertedPageFlags.NoProcess

      invertedPageRequest.ConvertOptions = convertOptions
      invertedPageRequest.RegionData = Nothing

      Dim invertedPageResponse As InvertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest)
      Console.WriteLine("Original image, inverted = {0}", invertedPageResponse.IsInverted)

      ' Invert the image
      Dim invertRequest As InvertRequest = New InvertRequest()
      invertRequest.ConvertOptions = convertOptions
      Dim colorProcessingClient As ColorProcessingServiceClient = New ColorProcessingServiceClient()
      Dim invertResponse As CommandResponse = colorProcessingClient.Invert(invertRequest)
      If Not invertResponse.Destination Is Nothing Then
         If TypeOf invertResponse.Destination Is RawBinaryData Then
            File.WriteAllBytes(invertedImageFileName, (TryCast(invertResponse.Destination, RawBinaryData)).Data)
         End If
      End If
      colorProcessingClient.Close()


      ' Check again
      convertOptions.Source = invertResponse.Destination
      invertedPageRequest.ConvertOptions = convertOptions
      invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest)
      Console.WriteLine("After running InvertCommand, inverted = {0}", invertedPageResponse.IsInverted)

      ' Now run the command to un-invert the image
      convertOptions.Source = invertedPageResponse.Destination
      invertedPageRequest.Flags = InvertedPageFlags.Process
      invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest)

      ' Now check the image again
      convertOptions.Source = invertedPageResponse.Destination
      invertedPageRequest.Flags = InvertedPageFlags.NoProcess
      invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest)
      Console.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPageResponse.IsInverted)
      If Not invertedPageResponse.Destination Is Nothing Then
         If TypeOf invertedPageResponse.Destination Is RawBinaryData Then
            File.WriteAllBytes(nonInvertedImageFileName, (TryCast(invertedPageResponse.Destination, RawBinaryData)).Data)
         End If
      End If
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void InvertedPageExample()
   {
      // 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");
      DocumentProcessingServiceClient documentProcessingClient = new DocumentProcessingServiceClient();

      RawBinaryData sourceBinaryData = new RawBinaryData();
      sourceBinaryData.Data = File.ReadAllBytes(tifFileName);

      RasterConvertOptions convertOptions = new RasterConvertOptions();

      convertOptions.Source = sourceBinaryData;
      convertOptions.Destination = null;
      convertOptions.Format = RasterImageFormat.Tif;
      convertOptions.FirstPage = 1;
      convertOptions.LastPage = 1;
      convertOptions.BitsPerPixel = 1;
      convertOptions.QualityFactor = 2;

      InvertedPageRequest invertedPageRequest = new InvertedPageRequest();
      invertedPageRequest.Flags = InvertedPageCommandFlags.NoProcess;

      invertedPageRequest.ConvertOptions = convertOptions;
      invertedPageRequest.RegionData = null;

      InvertedPageResponse invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest);
      Console.WriteLine("Original image, inverted = {0}", invertedPageResponse.IsInverted);

      // Invert the image
      InvertRequest invertRequest = new InvertRequest();
      invertRequest.ConvertOptions = convertOptions;
      ColorProcessingServiceClient colorProcessingClient = new ColorProcessingServiceClient();
      CommandResponse invertResponse = colorProcessingClient.Invert(invertRequest);
      if (invertResponse.Destination != null)
      {
         if (invertResponse.Destination is RawBinaryData)
            File.WriteAllBytes(invertedImageFileName, (invertResponse.Destination as RawBinaryData).Data);
      }
      colorProcessingClient.Close();


      // Check again
      convertOptions.Source = invertResponse.Destination;
      invertedPageRequest.ConvertOptions = convertOptions;
      invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest);
      Console.WriteLine("After running InvertCommand, inverted = {0}", invertedPageResponse.IsInverted);

      // Now run the command to un-invert the image
      convertOptions.Source = invertedPageResponse.Destination;
      invertedPageRequest.Flags = InvertedPageCommandFlags.Process;
      invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest);

      // Now check the image again
      convertOptions.Source = invertedPageResponse.Destination;
      invertedPageRequest.Flags = InvertedPageCommandFlags.NoProcess;
      invertedPageResponse = documentProcessingClient.InvertedPage(invertedPageRequest);
      Console.WriteLine("After running InvertedPageCommand, inverted = {0}", invertedPageResponse.IsInverted);
      if (invertedPageResponse.Destination != null)
      {
         if (invertedPageResponse.Destination is RawBinaryData)
            File.WriteAllBytes(nonInvertedImageFileName, (invertedPageResponse.Destination as RawBinaryData).Data);
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
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

IDocumentProcessingService Interface
IDocumentProcessingService Members
Cleaning Up 1-Bit Images
Smooth Method
BorderRemove Method
LineRemove Method
InvertedText Method
InvertedPage Method
DotRemove Method
HolePunchRemove Method
HighQualityRotate Method
Minimum Method
Maximum Method

 

 


Products | Support | Contact Us | Copyright Notices

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

Applications developed with LEADTOOLS WCF components require runtime licenses. Server licensing is required for applications on a server. For more information, refer to: Imaging Pro/Document/Medical