how to compare set of images in java using pixel based image comparision metric based on mean squared error?

后端 未结 3 826
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 00:07

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. Aft

相关标签:
3条回答
  • 2020-12-10 00:59

    You can do it using Catalano Framework. There's several metrics to compare image, including 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 these metrics are based in the book: Computer Imaging: Digital Image Analysis and Processing - Scott E Umbaugh.

    Next version (1.3) will contains Derivative SNR.

    0 讨论(0)
  • 2020-12-10 01:02
      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 讨论(0)
  • 2020-12-10 01:04

    Right now your code will compare always the file 2000.png with 2002.png. First refactor your comparison code into a method:

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

    Declare a class CompareResult to group the result info into one Message:

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

    Then expect a list of image files from commandline and compre them each to 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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题