Ask Your Question
1

Detect if image is blurry

asked 2013-07-17 08:42:58 -0600

mary gravatar image

updated 2015-10-28 04:20:08 -0600

Hello, I search a way to determine if an image is blurry or not in my Android application. I don't know opencv library and image processing but I read that I can use a Laplacian filter so I need help to understand how use it. Thank you!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-08-01 03:12:34 -0600

mary gravatar image

Finally I traslated a c++ good code that I had found in internet to java and it works very well. This is my code:

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap image = BitmapFactory.decodeByteArray(im, 0, im.length);
int l = CvType.CV_8UC1; //8-bit grey scale image
Mat matImage = new Mat();
Utils.bitmapToMat(image, matImage);
Mat matImageGrey = new Mat();
Imgproc.cvtColor(matImage, matImageGrey, Imgproc.COLOR_BGR2GRAY);

Bitmap destImage;
destImage = Bitmap.createBitmap(image);             
Mat dst2 = new Mat();
Utils.bitmapToMat(destImage, dst2);
Mat laplacianImage = new Mat();
dst2.convertTo(laplacianImage, l);
Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
Mat laplacianImage8bit = new Mat();
laplacianImage.convertTo(laplacianImage8bit, l);

Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(),
    laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(laplacianImage8bit, bmp);
int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(),
    bmp.getHeight());

int maxLap = -16777216;

for (int i = 0; i < pixels.length; i++) {
if (pixels[i] > maxLap)
    maxLap = pixels[i];
}

int soglia = -6118750;      

if (maxLap < soglia || maxLap == soglia) {
    Log.d(MIOTAG, "blur image");
}
edit flag offensive delete link more

Comments

Good to know :) Please accept your own answer as the solution, so the topic show solved.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-01 03:18:58 -0600 )edit

@mary Could you post the link to the C++ code please?

muglikar gravatar imagemuglikar ( 2015-06-13 03:27:56 -0600 )edit

Bitmap image = BitmapFactory.decodeByteArray(im, 0, im.length); In the above line i am getting an error that
Error:(385, 58) error: cannot find symbol variable im any help plz?

zahra gravatar imagezahra ( 2016-04-02 15:16:05 -0600 )edit

use im as byte[] datatype

psingla gravatar imagepsingla ( 2017-11-08 02:10:25 -0600 )edit
1

answered 2013-07-17 09:19:21 -0600

I guess google can be your friend after all. Start having a look at these topics:

  1. http://stackoverflow.com/questions/7765810/is-there-a-way-to-detect-if-an-image-is-blurry
  2. http://answers.opencv.org/question/3251/detect-blur-image/

Next time please put some effort into it. Topics like this will get closed if an exact same question is already available at the Q&A forum, like in second link...

edit flag offensive delete link more

Comments

1

I have searched in a carefully way before I posted this question, I have read the topics that you link but some of them are difficult to understand for me and other of them are written with language different from java, so I hoped to receive more help.

mary gravatar imagemary ( 2013-07-17 09:50:50 -0600 )edit

Question Tools

Stats

Asked: 2013-07-17 08:42:58 -0600

Seen: 17,489 times

Last updated: Aug 01 '13