How to compare a set of images in java using pixel-based image comparison metric based on standard error?

In my project, I have a set of images. I need to compare them. Each pixel from one image is compared with a pixel in one place in all other images in the data set. After applying the calculation of the mean square error to all pixels in the image space, a set of different pixels is determined that represent pixels with different color values ​​in the images. I compared and saved pixel similarities in a file for two images. But can not do it for 12 images. "The 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>widthe) { smw =widthe; } else { smw=width; } if(height>heighte) { smh=heighte; } else { smh=height; } //CHECKING NUMBER OF PIXELS SIMILARITY for(int a=0;a<smw;a++) { for(int b=0;b<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>widthe) { w=width; } else { w=widthe; } if(height>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); } } 
+1
java image-processing
Jan 17 '14 at 6:07
source share
3 answers

You can do this with the Catalano Framework . There are several indicators for comparing images, including the mean square error.

Example:

 FastBitmap original = new FastBitmap(bufferedImage1); FastBitmap reconstructed = new FastBitmap(bufferedImage2); ObjectiveFidelity o = new ObjectiveFidelity(original, reconstructed); // Error total int error = o.getTotalError(); //Mean Square Error double mse = o.getMSE(); //Signal Noise Ratio double snr = o.getSNR(); //Peak Signal Noise Ratio double psnr = o.getPSNR(); 

All of these metrics are based on the book: Computer Visualization: Digital Image Analysis and Processing - Scott E Umbaugh.

The next version (1.3) will contain a derivative of SNR .

+5
Feb 13 '14 at 19:30
source share

At the moment, your code will always compare the 2000.png file with 2002.png. First reformat your comparison code to a method:

 CompareResult compare(BufferedImage img1,BufferedImage img2) { ... } 

Declare a CompareResult class to group result information into a single message:

 class CompareResult { long pixMatched; long pixVar; ... } 

Then expect a list of image files from the command line and sum them up with each other:

 for(int i=0;i<args.length();i++) { BufferedImage img1 = ImageIO.read(args[i]); for (int j=i+1;j<args.length();j++) { BufferedImage img2 = ImageIO.read(args[j]); CompareResult r = compare(img1,img2); printInfo(r); } } 
+2
Jan 17 '14 at 9:58
source share
  File file1 = new File(args[0]); File file2 = new File(args[1]); boolean compareResult = FileUtils.contentEquals(file1, file2); System.out.println("Are the files are same? " + compareResult); 

Apache Commons IO library to perform this comparison (download commons-io-2.4.jar)

0
28 '16 at 5:42 on
source share



All Articles