I need to calculate the difference in pixels between two images in java on Android. The problem is that I have code that returns an inaccurate result.
eg. I have 3 very similar pictures, but to compare each of them they give significantly different results: 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);
}
String resultString = String.valueOf(intColor1);
}
double razlika = (((double)intColor1 - intColor2)/intColor2)*100;
}
It seems to me that I need to compare each pixel for both images (intColor1 (x, y) vs intColor2 (x, y)), but how can I do this, and later calculate the percentage difference?
source
share