 How to represent the difference on the image?

I have code to find the difference between two images. after finding the difference, i'm not getting an idea how to represent the different portion with any rectangular box.

Here is my code to find the difference.

``````package compareImages;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageComparision {
public static void main(String[] args) {
BufferedImage imgA = null;
BufferedImage imgB = null;

try {
File fileA = new File("E:\\Career\\A.jpg");
File fileB = new File("E:\\Career\\B.jpg");

} catch (IOException e) {
System.out.println(e);
}
int width1 = imgA.getWidth();
int width2 = imgB.getWidth();
int height1 = imgA.getHeight();
int height2 = imgB.getHeight();

if ((width1 != width2) || (height1 != height2))
System.out.println("Error: Images dimensions" + "mismatch");
else {
for (int y = 0; y < height1; y++) {
for (int x = 0; x < width1; x++) {
int rgbA = imgA.getRGB(x, y);
int rgbB = imgB.getRGB(x, y);
int redA = (rgbA >> 16) & 0xff;
int greenA = (rgbA >> 8) & 0xff;
int blueA = (rgbA) & 0xff;
int redB = (rgbB >> 16) & 0xff;
int greenB = (rgbB >> 8) & 0xff;
int blueB = (rgbB) & 0xff;

if ((redA == redB) || (greenA == greenB)|| (blueA == blueB)) {
System.out.println("Images are identical. no difference b.w two images..");
} else {
System.out.println("how to draw a rectangular box over the difference?????????");
}
}
}
}
}
}``````

Ex: image A have a radio button at position (50,50) and image B have checkbox at same position. now, i have to represent the checkbox which is on image B with a 2D rectangle box. Please give me ideas to achieve that.

Author: bandham.manikanta
Sort By:
Oldest
|