←Select platform

HolePunchRemove Method

Summary

Finds and removes hole punches. This operation is available in the Document/Medical Toolkits.

Syntax

C#
VB
C++
[FaultContractAttribute(System.Type)] 
[OperationContractAttribute(Action="HolePunchRemove", 
   AsyncPattern=false, 
   IsOneWay=false, 
   IsInitiating=true, 
   IsTerminating=false)] 
public DocumentResponse HolePunchRemove( 
   HolePunchRemoveRequest request 
) 
  
<OperationContractAttribute("HolePunchRemove")> 
<FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault,  
   Action="",  
   Name="",  
   Namespace="",  
   ProtectionLevel=ProtectionLevel.None,  
   HasProtectionLevel=False)> 
Function HolePunchRemove( _ 
   ByVal request As Leadtools.Services.Imageprocessing.Datacontracts.HolePunchRemoveRequest _ 
) As Leadtools.Services.Imageprocessing.Datacontracts.DocumentResponse 
[OperationContractAttribute("HolePunchRemove")] 
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault,  
   Action="",  
   Name="",  
   Namespace="",  
   ProtectionLevel=ProtectionLevel.None,  
   HasProtectionLevel=false)] 
Leadtools.Services.Imageprocessing.Datacontracts.DocumentResponse^ HolePunchRemove(  
   Leadtools.Services.Imageprocessing.Datacontracts.HolePunchRemoveRequest^ request 
)  

Parameters

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

Return Value

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

Remarks
  • This operation detects and removes hole punches that are common in scanned documents.
  • This operation works only on 1-bit black and white images.
  • Hole punch configurations may consist of 2 or more holes.
  • If a region is selected, only the selected region will be changed by this operation. If no region is selected, the whole image will be processed.
  • This operation does not support signed data images.
  • This operation does not support 32-bit grayscale images.
  • Before calling this operation, ensure that the hole punch is free of any other stray marks. If you do not, the hole will not be recognized. Use the LineRemove operation to remove any horizontal or vertical lines from the image. Use the other Document Cleanup operations to remove other imaging artifacts such as dots, blobs, borders, inverted text, bumps and nicks. This will have the added benefit of making your image smaller when compressed.

For example, the following image must have the vertical line removed:

Once the image has been cleaned, as shown in the following figure, the hole punch can be removed:

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

Example

C#
VB
using Leadtools.Services; 
 
public void HolePunchRemoveExample() 
{ 
   DocumentProcessingServiceClient client = new DocumentProcessingServiceClient(); 
 
   RawBinaryData sourceBinaryData = new RawBinaryData(); 
   sourceBinaryData.Data = File.ReadAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "clean.tif")); 
 
   RasterConvertOptions convertOptions = new RasterConvertOptions(); 
 
   convertOptions.Source = sourceBinaryData; 
   convertOptions.Destination = null; 
   convertOptions.Format = RasterImageFormat.Bmp; 
   convertOptions.FirstPage = 1; 
   convertOptions.LastPage = 1; 
   convertOptions.BitsPerPixel = 24; 
   convertOptions.QualityFactor = 2; 
 
   HolePunchRemoveRequest request = new HolePunchRemoveRequest(); 
 
   request.ConvertOptions = convertOptions; 
   request.RegionData = null; 
   request.Flags = HolePunchRemoveCommandFlags.GetRegion | HolePunchRemoveCommandFlags.UseDpi | HolePunchRemoveCommandFlags.UseCount | HolePunchRemoveCommandFlags.UseLocation; 
   request.MinimumHoleCount = 2; 
   request.MaximumHoleCount = 4; 
   request.MinimumHoleWidth = 0; 
   request.MinimumHoleHeight = 0; 
   request.MaximumHoleWidth = 0; 
   request.MaximumHoleHeight = 0; 
   request.Location = HolePunchRemoveCommandLocation.Left; 
 
   DocumentResponse response = client.HolePunchRemove(request); 
   if (response.Destination != null) 
   { 
      if (response.Destination is RawBinaryData) 
         File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "HolePunchRemove.bmp"), (response.Destination as RawBinaryData).Data); 
   } 
 
   if (response.Region != null) 
   { 
      Bitmap bitmap = new Bitmap(Path.Combine(LEAD_VARS.ImagesDir, "HolePunchRemove.bmp")); 
      Graphics graphics = Graphics.FromImage(bitmap); 
 
      Region region1 = new Region(); 
      RegionData regionData = region1.GetRegionData(); 
      regionData.Data = response.Region.Data; 
 
      Region region2 = new Region(regionData); 
 
      graphics.FillRegion(Brushes.Red, region2); 
 
      bitmap.Save(Path.Combine(LEAD_VARS.ImagesDir, "HolePunchRemoveRegion.bmp")); 
 
      region2.Dispose(); 
      region1.Dispose(); 
      bitmap.Dispose(); 
      graphics.Dispose(); 
   } 
 
   client.Close(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools.Services 
 
Public Sub HolePunchRemoveExample() 
   Dim client As DocumentProcessingServiceClient = New DocumentProcessingServiceClient() 
 
   Dim sourceBinaryData As RawBinaryData = New RawBinaryData() 
   sourceBinaryData.Data = File.ReadAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "clean.tif")) 
 
   Dim convertOptions As RasterConvertOptions = New RasterConvertOptions() 
 
   convertOptions.Source = sourceBinaryData 
   convertOptions.Destination = Nothing 
   convertOptions.Format = RasterImageFormat.Bmp 
   convertOptions.FirstPage = 1 
   convertOptions.LastPage = 1 
   convertOptions.BitsPerPixel = 24 
   convertOptions.QualityFactor = 2 
 
   Dim request As HolePunchRemoveRequest = New HolePunchRemoveRequest() 
 
   request.ConvertOptions = convertOptions 
   request.RegionData = Nothing 
   request.Flags = HolePunchRemoveCommandFlags.GetRegion Or HolePunchRemoveCommandFlags.UseDpi Or HolePunchRemoveCommandFlags.UseCount Or HolePunchRemoveCommandFlags.UseLocation 
   request.MinimumHoleCount = 2 
   request.MaximumHoleCount = 4 
   request.MinimumHoleWidth = 0 
   request.MinimumHoleHeight = 0 
   request.MaximumHoleWidth = 0 
   request.MaximumHoleHeight = 0 
   request.Location = HolePunchRemoveCommandLocation.Left 
 
   Dim response As DocumentResponse = client.HolePunchRemove(request) 
   If Not response.Destination Is Nothing Then 
      If TypeOf response.Destination Is RawBinaryData Then 
         File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "HolePunchRemove.bmp"), (TryCast(response.Destination, RawBinaryData)).Data) 
      End If 
   End If 
 
   If Not response.Region Is Nothing Then 
      Dim bitmap As Bitmap = New Bitmap(Path.Combine(LEAD_VARS.ImagesDir, "HolePunchRemove.bmp")) 
      Dim graphics As Graphics = graphics.FromImage(bitmap) 
 
      Dim region1 As Region = New Region() 
      Dim regionData As RegionData = region1.GetRegionData() 
      regionData.Data = response.Region.Data 
 
      Dim region2 As Region = New Region(regionData) 
 
      graphics.FillRegion(Brushes.Red, region2) 
 
      bitmap.Save(Path.Combine(LEAD_VARS.ImagesDir, "HolePunchRemoveRegion.bmp")) 
 
      region2.Dispose() 
      region1.Dispose() 
      bitmap.Dispose() 
      graphics.Dispose() 
   End If 
 
   client.Close() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.