两幅图像之间的Android java百分比位图像素差

两幅图像之间的Android java百分比位图像素差,java,android,image,bitmap,Java,Android,Image,Bitmap,我需要在Android上用java计算两幅图像之间的像素差。问题是我有返回不准确结果的代码 例如,我有3张非常相似的图片,但它返回的每个图片的比较结果都明显不同: pic1与pic2=1.71%;pic1与pic3=0.0045%;pic2与pic3=36.7% BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.ARGB_8888; opt.

我需要在Android上用java计算两幅图像之间的像素差。问题是我有返回不准确结果的代码

例如,我有3张非常相似的图片,但它返回的每个图片的比较结果都明显不同: pic1与pic2=1.71%;pic1与pic3=0.0045%;pic2与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;

}
BitmapFactory.Options opt=新建BitmapFactory.Options();
opt.inPreferredConfig=Bitmap.Config.ARGB_8888;
opt.inSampleSize=5;
位图mBitmap1=BitmapFactory.decodeFile(“/sdcard/pic1.jpg”,opt);
位图mBitmap2=BitmapFactory.decodeFile(“/sdcard/pic2.jpg”,opt);
int intColor1=0;
int intColor2=0;
对于(int x=0;x

我想我需要比较两幅图像的每个像素(intColor1(x,y)和intColor2(x,y)),但我如何才能做到这一点,以及以后如何计算百分比差异?

您使用的百分比公式是错误的。例如,#333333与#33333 2几乎相同(您的公式显示它们的差异为0.003%)。此外#323333与#333几乎相同,但您的公式显示它们有3%的差异

您应该提取每个颜色像素的每个组成位(color.red()、color.green()、color.blue()),计算它们之间的差异,然后得到组合的差异百分比


虽然这种获得两幅图像差异的方法简单有效,但有一个很大的警告:如果图像内容相同,但移动了一个像素(例如向右移动),您的方法将显示它们完全不同。

那么有没有有效的方法来计算android上的图像之间的差异(以百分比为单位)?代码将非常有用!谢谢,我必须把所有相似的图片都拿出来,请帮忙。。。