Solved

How detect a scanned image is blank page

Posted on 2011-03-22
15
1,641 Views
Last Modified: 2012-08-13
Hi,
I need JAI(java Advanced Imaging) program to detect whether a scanned image is blank page.
The page may varied grey background or some random dots because of scan quality or crumbled source paper.
0
Comment
Question by:Maverick_Cool
  • 8
  • 5
  • 2
15 Comments
 
LVL 27

Expert Comment

by:aburr
ID: 35194701
Look at the file size. A blank (or nearly so) file will be much smaller than one containing information.
0
 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35197242
Blank in sense, we have grey dots. And scan resolution may vary. This approach is not feasible.
I am looking something that analyse variance of grey/back ground color/paper color/quality.
0
 
LVL 27

Expert Comment

by:aburr
ID: 35200797
Convert to jpg and look for file size there. If the picture is uniform, the file size will be unusually low.
This is a difficult problem because it is difficult to tell the difference between noise and picture
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35201076
I would dilate the image (morphalogical open), this would remove most of the small dots, then I would take the average and standard deviation of the luminance (grey value). If the average is high and the deviation is low, the page is probably blank.
0
 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35204217
hmm, sounds great.
But can you show example this using JAI, Java advanced Imaging.
0
 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35206526
Can please show same JAI(Java Advanced Image) code example
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
ID: 35208047
This link shows an example using erode. The 'kernal' is the shape to use for the operation.
http://snippets.dzone.com/posts/show/2974
The kernal can be used like this
KernelJAI(int width, int height, int xOrigin, int yOrigin, float[] data)

I would probably use
KernelJAI(5, 5, 2, 2, new float[] {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}) //25 1s
Just make sure the origin is in the center and play with it until you get what you want.
Average is just sum/count
Variance is just sum of all (value - average)^2/count
Standard deviation is sqare root of variance.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35210271
what will data in my case.
I have the TIF file loaded to variable.
how do i process it.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35210382
What kind of variable are you loading it into? Did you use the code from the link? It uses a BufferedImage.
0
 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35210408
i got that,
 i want know what is the
new float[] {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}) //25 1s

width and hieght has to taken from the image properties
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35210581
Ah, I see where the confusion is. The width and height are for the dilation kernal not the image. It's telling it the shape to use to dilate. So, the example I posted uses a 5x5 rectangle for dlation/erosion. Those numbers should be low. If you do it like
new float[] {0,0,1,0,0,
                   0,1,1,1,0,
                   1,1,1,1,1,
                   0,1,1,1,0,
                   0,0,1,0,0})
Then it will use a diamond shape for the operation.
Experiment with different sizes. a 3x3 may be good enough if the dots are small.

Oh, change the word "erode" to "dilate" too. Erode extends the black and dilate extends the white. So to extend the white over the black dots, you need "dilate".
0
 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35220169
Let me check this. Thanks all.
0
 
LVL 7

Author Comment

by:Maverick_Cool
ID: 35239613
Hi Tommy,
how to do this with renderedimage:
1. Average is just sum/count
2. Variance is just sum of all (value - average)^2/count
Standard deviation is sqare root of variance.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35243114
Most of this is detailed here:
http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Image-manipulation.doc.html

There's a mean function. Looks something like
double[] mean = (double[])someImage.getProperty("mean");

There is no standard deviation property, but if you know any statistics, you probably know that the mean of the squares minus the square of the mean gives you the standard deviation. (If you don't know statistics, then take my word for it)
So multiply the image by itself, take the mean of that, and subtract the square of the other mean

(Note: Again, I don't use JAI much, I just know a lot of math and image processing techniques. I use OpenCV with C++ usually, but I think this will get you close enough to where you can get it working).

     RenderedImage img;
//Scan image
     double[] mean = (double[])img.getProperty("mean");

     ParameterBlock pb;

     pb = new ParameterBlock();
     pb.addSource(img);
     pb.addSource(img);

     RenderedImage squares = JAI.create("multiply", pb, null);

     double[] meanSq = (double[])squares.getProperty("mean");

     double[] standardDev = meanSq - mean*mean

Open in new window

0
 
LVL 7

Author Closing Comment

by:Maverick_Cool
ID: 35301453
thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now