I have written some code that compares two "BufferedImage" rectangles by doing a pixel by pixel comparison. These BufferedImages are of "playing cards" with rounded corners so I would like to exclude those corner areas during the image comparison process since the varied background could cause the comparison to be "false".
For example, two screenshots of identical cards taken from different locations of the screen will "not match" because the backgrounds are different. If I could exclude the corner area from the comparison, they WOULD match. I could add a bunch of "if" statements like...
if ( (j = 1 && i < 10) ||
(j = 2 && i < 6) ||
(j = 3 && i < 5) ||
(j = 4 && i < 4) ||
(j = 5 && i < 3) ||
(j = 6 && i < 2) ||
(j = 7 && i < 1) ||
(j = 8 && i < 1) ||
(j = 9 && i < 1) ) {
i++;
break: skip;
}
...but it seems like there would be a more simple and elegant way of excluding these rounded corner areas from the process.
Here is the code without any "corner exclusion" code...
/****************************************************************
* CompareTwoImages
****************************************************************/
public static boolean CompareTwoImages(BufferedImage bImage1, BufferedImage bImage2) {
boolean ret = true;
int CardWidth = 25;
int CardHeight = 61;
int pixel1;
int pixel2;
int tolerance = 0;
try {
for (int j = 0 ; j < CardHeight; j++) { // for each card height pixel
for (int i = 0; i < CardWidth; i++) { // for each card width pixel
pixel1 = bImage1.getRGB(i, j);
pixel2 = bImage2.getRGB(i, j);
if ((pixel1 < (pixel2 - tolerance)) || (pixel1 > (pixel2 + tolerance))) {
ret = false;
}
}
}
} catch (Exception e) {
System.err.println("CompareTwoImages >>>> " + e.getMessage());
}
return ret;
}