我需要計算Android上java中兩個圖像之間的像素差異。問題是我有代碼返回不準確的結果。Android java百分比位圖兩個圖像之間的像素差異
例如我有3個非常相似的圖片,但它們返回的結果明顯不同: 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)),但我怎麼能做到這一點,並在以後計算百分比差異?
我必須獲取並列出所有類似的圖片將幫助你... – 2018-01-04 06:45:10