/** * Returns the number of black and white differences between the template and exam file. * * @param img Image of exams * @param x x start coordinate of the file * @param y y start coordinate of the file * @param template Template of exams * @param dump Dump to screen * @return The difference */ public static double templateXOR( Gray8Image img, int x, int y, Gray8Image template, boolean dump) { int diff = 0, total = 0; for (int j = y; j < y + template.getHeight() && j < img.getHeight(); j++) { for (int i = x; i < x + template.getWidth() && i < img.getWidth(); i++) { // XXX boolean isblack = (img.getSample(i, j) < 200 ? true : false); // if(dump) { System.out.print((isblack // & template.isWhite(i - x, j - y) ? "1" : ((!isblack) // & template.isBlack(i - x, j - y)) ? "-" : "0")); } if ((isblack & template.isWhite(i - x, j - y) | (!isblack) & template.isBlack(i - x, j - y))) { diff++; } total++; } // if(dump) { System.out.println(); } } return ((double) diff) / total; }