Answer / Solution:
Sometimes it is necessary to ask the customer for some test documents. The customer would gladly provide test documents, but has difficulty in doing so, because of sensitive information that is printed on the documents. The following describes how to use the KTM Project Builder to blank out regions from the document, so that the customer can provide some test documents.
Blanking out regions can also be used as a kind of image clean, before performing OCR, if the KTM image clean methods are not adequate enough.
This can be done temporarily or permanently. In the example below you can see how the patients name, D.O.B., address and health number have been blanked out:
The solution above was done with the combination of scripting and a Format Locator. The Format Locator was defined for that specific region and with scripting the area is removed and a new image is saved under the name "Test". Below is the sample project and script code:
Remove Area on a Document (KTM 6.2.1)
'##### Project Script #####
'#####################################################################################################################
'## This example script describes how to "blank out" regions of an image
'## ------------------------------------------------------------------------------------------------------------------
'## Reference:
'## 1. Kofax Cascade Forms Processing
'#####################################################################################################################
Option Explicit
Private Sub Document_BeforeClassifyXDoc(ByVal pXDoc As CASCADELib.CscXDocument, ByRef bSkip As Boolean)
Dim i As Integer
Dim j As Integer
Dim oImage As CscImage '## Actual image
Dim oNewImage As CscImage '## Temporary image
Dim XResolution, YResolution As Long
Dim oRegions As CscLocatorRegions '## RegionS
Dim oRegion As CscLocatorRegion '## Region
Dim sPath As String '## Path name of the folder where the images are stored
Dim sSourceFileName As String '## Path name and image file name, i.e. complete path name
'## Use this varaible, if you want to permanently replace the image
'# Remove any representations, before proceeding to blank out regions
For i = pXDoc.Representations.Count -1 To 0 Step -1
pXDoc.Representations.Remove(i)
Next
'# Blank out regions
For i = 0 To pXDoc.CDoc.Pages.Count -1
Set oImage = pXDoc.CDoc.Pages(i).GetImage '## Page from the pXDoc
Set oNewImage = oImage '## A temporary copy of the original page
sPath = pXDoc.CDoc.Pages(i).DisplayImageFilename
sSourceFileName = pXDoc.CDoc.Pages(i).SourceFileName
XResolution = oImage.XResolution
YResolution = oImage.YResolution
'# These blank out regios/areas have been defined as Regions in the class BlankOutRegions locator method FL_Regions
Set oRegions = Project.ClassByName("BlankOutRegions").Locators.ItemByName("FL_Regions").LocatorRegions
For j = 0 To oRegions.GetRegionCount -1
Set oRegion = oRegions.GetRegion(j)
oNewImage.EraseRect(MmToPix(oRegion.Left, XResolution), MmToPix(oRegion.Top, YResolution), MmToPix(oRegion.Width, XResolution), MmToPix(oRegion.Height, YResolution))
Next
'# Save the image to the hard drive, either under a different name or replacing the original
oNewImage.Save(sPath & "\Test.tif") '## Different name
'oNewImage.Save(sSourceFileName) '## Replace the original
Next
End Sub
Private Function MmToPix(dZoneValue As Double, dResolution As Double) As Double
MmToPix = dZoneValue / 25.4 * dResolution
End Function
Private Function PixelToMM(DocumentResolution As Double, Pixel As Double) As Double
PixelToMM = (25.4 * Pixel)/DocumentResolution
End Function
Applies to:
Product
Version
Category
KTM
6.3
Scripting
KTM
6.2
Scripting