Solved

How detect a scanned image is blank page

Posted on 2011-03-22
15
1,681 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

809 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