licornea_tools
psnr.cc
Go to the documentation of this file.
1 #include "../lib/common.h"
2 #include "../lib/args.h"
3 #include "../lib/opencv.h"
4 #include <iostream>
5 #include <string>
6 
7 using namespace tlz;
8 
9 
10 int main(int argc, const char* argv[]) {
11  get_args(argc, argv, "image1.png image2.png");
12  std::string image1_filename = in_filename_arg();
13  std::string image2_filename = in_filename_arg();
14 
15  cv::Mat mat1 = cv::imread(image1_filename, CV_LOAD_IMAGE_COLOR);
16  cv::Mat mat2 = cv::imread(image2_filename, CV_LOAD_IMAGE_COLOR);
17 
18  cv::Mat squared_difference;
19  cv::absdiff(mat1, mat2, squared_difference);
20  squared_difference.convertTo(squared_difference, CV_32F);
21  squared_difference = squared_difference.mul(squared_difference);
22 
23  cv::Scalar s = cv::sum(squared_difference);
24  double sse = s.val[0] + s.val[1] + s.val[2];
25 
26  double psnr = 0.0;
27  if(sse > 1e-10) {
28  double mse = sse / (double)(mat1.channels() * mat1.total());
29  psnr = 10.0 * log10((255 * 255) / mse);
30  }
31 
32  std::cout << psnr << std::endl;
33 }
34 
std::string in_filename_arg()
Definition: args.cc:98
int main(int argc, const char *argv[])
Definition: psnr.cc:10
void get_args(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:49