• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2050
  • Last Modified:

How detect a scanned image is blank page

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
Maverick_Cool
Asked:
Maverick_Cool
  • 8
  • 5
  • 2
1 Solution
 
aburrCommented:
Look at the file size. A blank (or nearly so) file will be much smaller than one containing information.
0
 
Maverick_CoolAuthor Commented:
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
 
aburrCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
TommySzalapskiCommented:
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
 
Maverick_CoolAuthor Commented:
hmm, sounds great.
But can you show example this using JAI, Java advanced Imaging.
0
 
Maverick_CoolAuthor Commented:
Can please show same JAI(Java Advanced Image) code example
0
 
TommySzalapskiCommented:
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
 
Maverick_CoolAuthor Commented:
what will data in my case.
I have the TIF file loaded to variable.
how do i process it.
0
 
TommySzalapskiCommented:
What kind of variable are you loading it into? Did you use the code from the link? It uses a BufferedImage.
0
 
Maverick_CoolAuthor Commented:
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
 
TommySzalapskiCommented:
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
 
Maverick_CoolAuthor Commented:
Let me check this. Thanks all.
0
 
Maverick_CoolAuthor Commented:
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
 
TommySzalapskiCommented:
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
 
Maverick_CoolAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 8
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now