Comparison of an image with others (analyze whether the chosen image is the same as the others already predefined or not)

I am trying to make a code in Java that compares an input image with other N images already defined in the code. I developed, with help (a lot), a similar code, that compared two images only, the problem is to enlarge it. Take a single image and go out comparing with several others, I'm not knowing how to do.

What I have:

public static boolean compareImage(BufferedImage image1, BufferedImage image2){
    if (image1.getWidth()!= image2.getWidth()|| image1.getHeight() != image2.getHeight()){
        return(false);
                }
    for (int x=0; x<image1.getWidth(); x++){
        for(int y=0; y<image1.getHeight(); y++){
            if(image1.getRGB(x,y)!=image2.getRGB(x,y)){
                return(false);
Author: Bruno Almeida, 2017-03-26

1 answers

You can store the images in a list, and make a loop to compare that list with the image you want, using the method of your code. Within this loop, you add a condition to do something when the comparison of the main image and some of the list returns true or false:

ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>();


for(int i = 0; i < imageList.size(); i++) {
   if(compareImage(image1, imageList.get(i))) {
      //faz algo se retornar true
   } else {
     //faz algo se retornar false
   }
}
 1
Author: , 2017-03-26 16:52:23