// Note: This can probably be optimized if all pixels are direct-grabbed // and image2 is expendable (then you can use it as output?) static BufferedImage imageChangeOverlay(BufferedImage image1, BufferedImage image2) { assertSameSize(image1, image2); int w = image1.getWidth(), h = image1.getHeight(), n = w*h; int[] pixels1 = pixelsOfBufferedImage(image1); int[] pixels2 = pixelsOfBufferedImage(image2); int[] pixelsOut = new[n]; for i to n: { int rgb = pixels1[i]; pixelsOut[i] = rgb == pixels2[i] ? 0 : rgb; } ret newBufferedImage(w, h, pixelsOut); }