两幅图像之间的Andr​​oid的Java个位图像素差 [英] Android java percentage bitmap pixel difference between two images

查看:108
本文介绍了两幅图像之间的Andr​​oid的Java个位图像素差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算在Java中的两个图像在Android之间的像素差别。问题是,我有code返回不准确的结果。

I need to calculate pixel difference between two images in java on Android. The problem is that I have code that return inaccurate result.

例如。我有3个非常相似的图片,但它返回显著不同的结果为他们每个人的比较: PIC1 VS PIC2 = 1.71%; PIC1 VS PIC3 = 0.0045%; PIC2 VS PIC3 = 36.7%。

E.g. I have 3 very similar pictures but it returns significantly different results for comparison of each of them: pic1 vs pic2 = 1.71%; pic1 vs pic3 = 0.0045%; pic2 vs pic3 = 36.7%.

BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
    opt.inSampleSize = 5;
    Bitmap mBitmap1 = BitmapFactory.decodeFile("/sdcard/pic1.jpg", opt);
    Bitmap mBitmap2 = BitmapFactory.decodeFile("/sdcard/pic2.jpg", opt);

    int intColor1 = 0;
    int intColor2 = 0;
    for (int x = 0; x < mBitmap1.getWidth(); x++) {
       for (int y = 0; y < mBitmap1.getHeight(); y++) {
            intColor1 = mBitmap1.getPixel(x, y);
            intColor2 = mBitmap2.getPixel(x, y); 
            //System.out.print(" ("+ x + ","+ y +") c:" + intColor1);   
       }
       String resultString = String.valueOf(intColor1);

    }
    //now calculate percentage difference
    double razlika = (((double)intColor1 - intColor2)/intColor2)*100;

}

我想,我需要每个像素比较两个图像(intColor1(X,Y)与intColor2(X,Y)),但我怎么能做到这一点,并在以后计算百分比差异?

I think that I need to compare each pixel for both images (intColor1(x,y) vs intColor2(x,y)), but how I can do that, and to later calculate percentage difference?

推荐答案

是您正在使用的百分比公式是错误的。例如,#333333是几乎相同的#333332(和你的公式显示他们是0.003%不同)。另外#323333几乎等同于#333333,但您的公式表明,他们是3%不同。

The percentage formula that you're using is wrong. For example, #333333 is almost identical to #333332 (and your formula shows they're 0.003% different). Also #323333 is almost identical to #333333, but your formula shows they're 3% different.

您应该提取每个颜色的像素组成的每个位(Color.red(),Color.green(),Color.blue()),计算出每个人的差别,进而获得了不同的组合比例。

You should extract each composing bit of each color pixel (Color.red() , Color.green(), Color.blue() ), calculate the difference of each of them, and then get the combined difference percentage.

虽然得到两个图像的差分的这种方法是简单和有效的,它有一个大的警告:如果这两个图像在内容上相同的,但由一个像素移位(到例如向右),你的方法将显示他们作为完全不同的。

While this method of getting the difference of the two images is simple and efficient, it has a big caveat: if the images are identical in content but shifted by one pixel (to the right for example), your method will show them as completely different.

这篇关于两幅图像之间的Andr​​oid的Java个位图像素差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆