Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find given bitmap image is blurred image or unblurred image in android

In my android application i need to find given/camera capturing image is blurred or not. i using following code from help of openCV library. but it will not give always correct result. please help me, thanks in advance.

private boolean isBlurredImage(Bitmap image) {
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inDither = true;
    opt.inPreferredConfig = Bitmap.Config.ARGB_8888;

    int l = CvType.CV_8UC1;
    Mat matImage = new Mat();
    Utils.bitmapToMat(image, matImage);
    Mat matImageGrey = new Mat();
    Imgproc.cvtColor(matImage, matImageGrey, Imgproc.COLOR_BGR2GRAY);

    Mat dst2 = new Mat();
    Utils.bitmapToMat(image, dst2);

    Mat laplacianImage = new Mat();
    dst2.convertTo(laplacianImage, l);
    Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
    Mat laplacianImage8bit = new Mat();
    laplacianImage.convertTo(laplacianImage8bit, l);
    System.gc();

    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());
    if (bmp != null)
        if (!bmp.isRecycled()) {
            bmp.recycle();

        }
    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.i(MIOTAG, "--------->blur image<------------");
        return true;
    } else {
        Log.i(MIOTAG, "----------->Not blur image<------------");
        return false;
    }
}
like image 422
challa sathish kumar Avatar asked Jan 02 '26 00:01

challa sathish kumar


1 Answers

This is one of the best articles regarding Out Of Focus images I've read. It's made by HP researchers and it's implemented in some of their cameras. It basically splits the image into small squares (as in a grid) and computes the blur factor for every region. After that, based on a decision tree it makes the final decision (blurry image or not).

I hope this will help you accomplish your work.

Best regards!

like image 165
rhcpfan Avatar answered Jan 04 '26 11:01

rhcpfan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!