forked from JeffOwOSun/gpu-bm3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcal_psnr.cpp
More file actions
67 lines (62 loc) · 1.79 KB
/
cal_psnr.cpp
File metadata and controls
67 lines (62 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <stdio.h>
#include <string>
#define cimg_display 1
#define cimg_use_png
#include "Cimg.h"
#include <getopt.h>
#include <math.h>
using namespace cimg_library;
using namespace std;
void usage(const char* progname) {
printf("Usage: %s [options] refImage noisyImage\n", progname);
printf("Program Options:\n");
printf(" -r reference image\n");
printf(" -n noisy image\n");
}
float get_mse(unsigned char* img1, unsigned char* img2, int width, int height) {
float mse = 0.0f;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
float a = (float)img1[i + j * width];
float b = (float)img2[i + j * width];
mse += (a-b) * (a-b);
}
}
return mse / (width * height);
}
int main(int argc, char** argv)
{
int opt;
int channels = 1;
int step = 2;
int verbose = 0;
int sigma = 0;
string ref_file, noisy_file;
while ((opt = getopt(argc, argv, "r:n:")) != EOF) {
switch (opt) {
case 'r':
ref_file = optarg;
break;
case 'n':
noisy_file = optarg;
break;
default:
usage(argv[0]);
return 1;
}
}
if (ref_file.length() == 0 || noisy_file.length() == 0) {
usage(argv[0]);
return 1;
}
CImg<unsigned char> ref_img(ref_file.c_str());
CImg<unsigned char> noisy_img(noisy_file.c_str());
if (ref_img.width() != noisy_img.width() || ref_img.height() != noisy_img.height()) {
printf("Image dimension not match\n");
return 1;
}
float mse = get_mse(ref_img.data(), noisy_img.data(), ref_img.width(), ref_img.height());
float psnr = 20 * log10(255) - 10 * log10(mse);
printf("PSNR: %f\n", psnr);
}