Home : WingScan Web Scanning : Detect a blank scanned page
Q10050 - HOWTO: Detect a blank scanned page

NOTE: This KB article contains somewhat outdated examples. DotImage has a BlankPageDetectionCommand which is a bit more "intelligent" about its detection. This article is being maintained as the methods described are still useful in some cases.

If you ever need to detect blank pages, you can use the GetDocumentHistogram method from the Histogram class.  Here is an example that's specific to our DotTwain Acquisition classes ImageAcquired event.

[C#]
private void OnImageAcquired(object sender, AcquireEventArgs e)
{
try
{
if (e.Image != null)
{
// Convert to an AtalaImage. (assuming you are using DotTwain)
AtalaImage img = AtalaImage.FromBitmap(e.Image);


// We need a 1-bit image.
AtalaImage tmp = img.GetChangedPixelFormat(PixelFormat.Pixel1bppIndexed);
img.Dispose();

// Check for separator.
Histogram hist = new Histogram(tmp);
int[] doc = hist.GetDocumentHistogram();
float tolerance = (doc[0] + doc[1]) * 0.005f;

// If black is greater than the tolerance, it's a real page.
if (doc[1] > tolerance)
{
// Save the page.
}
tmp.Dispose();
}
}
catch{}
}




[Visual Basic]
Private  Sub OnImageAcquired(ByVal sender As Object, ByVal e As AcquireEventArgs) Handles Twain.ImageAcquired
    Try
        If Not e.Image Is Nothing Then
            ' Convert to an AtalaImage. (assuming you are using DotTwain)
            Dim img As AtalaImage = AtalaImage.FromBitmap(e.Image)
 
            ' We need a 1-bit image.
            Dim tmp As AtalaImage = img.GetChangedPixelFormat(PixelFormat.Pixel1bppIndexed)  img.Dispose()
 
            ' Check for separator.
            Dim hist As Histogram = New Histogram(tmp)
            Dim doc() As Integer = hist.GetDocumentHistogram()
            Dim tolerance As single = (doc(0) + doc(1)) * 0.005f
 
            ' If black is greater than the tolerance, it's a real page.
            If doc(1) > tolerance Then
                ' Save the page.
            End If
 
            tmp.Dispose()
        End If
    End Try
End Sub

If you find some pages which are not blank are being detected as blank, you can decrease the percentage used to calculate the tolerance.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved