Example #1
0
  // Compute a modified version of the PSNR that takes into account only errors
  // that can be detected by the Human Visual System. Only one channel.
  // Color model must be YUV444 or YUV420.
  // return psnr * 1024 or INFINITE_PSNR (=0)
  public int computePSNR_HVS_M(
      int[] src, int[] dst, int x, int y, int w, int h, int channelIdx, ColorModelType type) {
    if ((type != ColorModelType.YUV420)
        && (type != ColorModelType.YUV422)
        && (type != ColorModelType.YUV444))
      throw new IllegalArgumentException("Invalid image type: must be YUV 420, 422 or 444");

    if ((channelIdx != 0) && (channelIdx != 1) && (channelIdx != 2))
      throw new IllegalArgumentException(
          "Invalid channel index: must be 0 for Y, 1 for U or 2 for V");

    if ((x < 0) || (y < 0))
      throw new IllegalArgumentException("Illegal argument: x and y must be positive or null");

    if ((w <= 0) || (h <= 0))
      throw new IllegalArgumentException("Illegal argument: w and h must be positive");

    if (src == dst) return 0;

    final int mse = computeCSFDeltaAvg(src, dst, x, y, w, h, channelIdx);

    if (mse <= 0) return Global.INFINITE_VALUE;

    // Formula:  double mse = (double) (sum) / size
    //           double psnr = 10 * Math.log10(255d*255d/mse);
    // Calculate PSNR << 10 with 1024 * 10 * (log10(65025L) = 49286
    return 49286 - Global.ten_log10(mse);
  }
Example #2
0
  // return psnr * 1024 or INFINITE_PSNR (=0)
  public int computePSNR(
      int[] data1, int[] data2, int x, int y, int w, int h, ColorModelType type) {
    final long lsum = this.computeDeltaSum(data1, data2, x, y, w, h, type);

    // Rescale to avoid overflow
    final int isum = (int) ((lsum + 50) / 100);

    if (isum <= 0) return Global.INFINITE_VALUE;

    // Formula:  double mse = (double) (sum) / size
    //           double psnr = 10 * Math.log10(255d*255d/mse);
    // or        double psnr = 10 * (Math.log10(65025) + (Math.log10(size) - Math.log10(sum))
    // Calculate PSNR << 10 with 1024 * 10 * (log10(65025L) = 49286
    // 1024*10*log10(100) = 20480
    final int iterations = ((w - x) >> this.downSampling) * ((h - y) >> this.downSampling);
    return 49286 + (Global.ten_log10(iterations) - Global.ten_log10(isum)) - 20480;
  }