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

Asked

Viewed 912 times

0

I’m trying to make a code in Java that compares an input image with other n images already defined in the code. I developed, with (quite) help, a similar code, which compared two images only, the problem is to enlarge it. Take a single image and go comparing with several others, I’m not able to do.

What I got:

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);
  • How about transforming the images to be compared into a list and make a loop passing each entry of that list as a parameter, and the image you want to compare with this list as another parameter?

  • It’s exactly the part of making this list that I get lost in, I don’t know exactly how to list the images.

1 answer

1


You can store the images in a list, and make a loop to compare this list with the image you want, using your code method. Within this loop, you add a condition to do something when the main image comparison and some of the list return 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
   }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.