Solved

How detect a scanned image is blank page

Posted on 2011-03-22
15
1,663 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
best (free) software to access postgres db (java) 1 32
javap not working 8 37
tomcat not starting 6 31
MySQL  on Tomcat 8 29
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

920 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

14 Experts available now in Live!

Get 1:1 Help Now