title: how to compare set of images in java using pixel based image comparision metric based on mean squared error?
body: <p>In my project i have a set of images. I need to compare them. Each pixel from one image is compared to the pixel at the same location in all other images in the dataset. After applying mean squared error calculation to all of the pixels in image space, a set of different pixels are identified which represents pixels with varying color values in the images. 
  I have compared and stored similarities pixels in a file for two images.but can't do this for 12 images.'code'</p>
  
  <pre><code>import java.io.*;
  import java.awt.*;
  import javax.imageio.ImageIO;
  import java.awt.image.BufferedImage;
  class spe
  {
      public static void main(String args[]) 
      throws IOException
      {
          long start = System.currentTimeMillis();
          int q=0;
              File file1 = new File("filename.txt");
  
          /* if file doesnt exists, then create it
          if (!file.exists()) {
                      file.createNewFile();
                  }*/
          FileWriter fw = new FileWriter(file1.getAbsoluteFile());
          BufferedWriter bw = new BufferedWriter(fw);
  
                  File file= new File("2000.png");
              BufferedImage image = ImageIO.read(file);
          int width = image.getWidth(null);
              int height = image.getHeight(null);
          int[][] clr=  new int[width][height]; 
          File files= new File("2002.png");
              BufferedImage images = ImageIO.read(files);
          int widthe = images.getWidth(null);
              int heighte = images.getHeight(null);
          int[][] clre=  new int[widthe][heighte]; 
          int smw=0;
          int smh=0;
          int p=0;
              //CALUCLATING THE SMALLEST VALUE AMONG WIDTH AND HEIGHT
              if(width&gt;widthe)
              { 
                  smw =widthe;
              }
              else 
              {
                  smw=width;
              }
              if(height&gt;heighte)
              {
                  smh=heighte;
              }
              else 
              {
                  smh=height;
              }
              //CHECKING NUMBER OF PIXELS SIMILARITY
              for(int a=0;a&lt;smw;a++)
              {
                  for(int b=0;b&lt;smh;b++)
                  {
                      clre[a][b]=images.getRGB(a,b);
                      clr[a][b]=image.getRGB(a,b);
                      if(clr[a][b]==clre[a][b]) 
                      {
                          p=p+1;
                          bw.write("\t");
                           bw.write(Integer.toString(a));
                          bw.write("\t");
                           bw.write(Integer.toString(b)); 
                          bw.write("\n");
                      }
                      else
                          q=q+1;
                  }
              }
  
      float w,h=0;
      if(width&gt;widthe) 
      {
          w=width;
      }
      else 
      {
          w=widthe;
      }
      if(height&gt;heighte)
      { 
          h = height;
      }
      else
      {
          h = heighte;
      }
      float s = (smw*smh);
      //CALUCLATING PERCENTAGE
      float x =(100*p)/s;
  
      System.out.println("THE PERCENTAGE SIMILARITY IS APPROXIMATELY ="+x+"%");
      long stop = System.currentTimeMillis();
      System.out.println("TIME TAKEN IS ="+(stop-start));
      System.out.println("NO OF PIXEL GETS VARIED:="+q);
      System.out.println("NO OF PIXEL GETS MATCHED:="+p);
    }
  }
  </code></pre>