annotate Meerwald/cmp_dwt.c @ 20:bd669312f068

suppress warnings, fix link errors
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:54:58 +0100
parents f83ef905a63d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "dwt.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 #include "coeff.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 #include "gray.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 #include "pgm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 #include "dwt_util.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 char *progname;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 void usage(void) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "usage: %s [-e n] [-f n] [-F file] [-h] [-l n] [-o file] [-pP] [-s name,..] -i file file\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-e n\t\twavelet filtering method (default: 2)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 fprintf(stderr, "\t-f n\t\tfilter number (default: 2)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 fprintf(stderr, "\t-F file\t\tfilter definition file (default: filter.dat\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-i file\t\toriginal image file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-l n\t\tmax. decomposition level (default: 0 = max)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-m n\t\tmultiplication factor (default: 0 = auto)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-o file\t\toutput file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 fprintf(stderr, "\t-p\t\tprint PSNR, RMS and MSE\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 fprintf(stderr, "\t-P\t\tonly print PSNR, RMS and MSE, no difference image\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 fprintf(stderr, "\t-q\t\tprint PSNR, RMS and MSE per subband\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 fprintf(stderr, "\t-s name,...\tsubband/level (default: all subbands)\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 fprintf(stderr, "\t-v n\t\tverbosity level\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 void process_subband_var(gray **output, int cols, int rows, Image_tree p, Image_tree q, int type, double min, double max, gray maxval) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 int col, row, startcol, startrow;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 if (!p || !q) return;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 calc_subband_location(cols, rows, type, p->level, &startcol, &startrow);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 for (row = 0; row < p->image->height; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 for (col = 0; col < p->image->width; col++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 double diff = fabs(get_pixel(p->image, col, row) - get_pixel(q->image, col, row));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 output[startrow + row][startcol + col] = PIXELRANGE((double) (diff - min) / (double) (max - min) * maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 void process_subband_fixed(gray **output, int cols, int rows, Image_tree p, Image_tree q, int type, double m) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 int col, row, startcol, startrow;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 if (!p || !q) return;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 calc_subband_location(cols, rows, type, p->level, &startcol, &startrow);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 for (row = 0; row < p->image->height; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 for (col = 0; col < p->image->width; col++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 double diff = fabs(get_pixel(p->image, col, row) - get_pixel(q->image, col, row));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 output[startrow + row][startcol + col] = PIXELRANGE(diff * m);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 void print_subband_psnr(int type, int level, double error, int cols, int rows, double min, double max, FILE *print) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 double mse = error / (double) (cols * rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 double rmse = sqrt(mse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 double psnr = 20.0 * log(255.0 / rmse) / log(10.0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 int startcol, startrow;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 calc_subband_location(cols << level, rows << level, type, level, &startcol, &startrow);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 fprintf(print, "%s%d (%d x %d) at %d x %d\n", subband_name(type), level, cols, rows, startcol, startrow);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 if (mse > 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 fprintf(print, " PSNR: %lf dB\n", psnr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 fprintf(print, " PSNR: inf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 fprintf(print, " RMS: %lf\n", rmse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 fprintf(print, " MSE: %lf\n", mse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 fprintf(print, " dmin, dmax: %lf, %lf\n", min, max);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 FILE *orig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 FILE *print;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 gray **input_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 gray **orig_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 Image_tree input_dwts, p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 Image_tree orig_dwts, q;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 gray **output;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 char orig_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 char *subband_list = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 int in_cols, in_rows, in_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 gray in_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 int orig_cols, orig_rows, orig_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 gray orig_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 int cols, rows, format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 gray maxval;
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
96 int row;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 int no_orig = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 int m = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 int maxlevel = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 int filter = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 int method = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 int levels;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 char filter_name[MAXPATHLEN] = "filter.dat";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 double error = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 int print_psnr = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 int print_psnr_subband = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 int print_psnr_only = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 double min, max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 pgm_init(&argc, argv); wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 while ((c = getopt(argc, argv, "e:f:F:h?i:l:m:o:pPqs:v:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 case 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 method = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 if (method < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 case 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 filter = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 if (filter <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 case 'F':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 strcpy(filter_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 case 'i':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 if (!strcmp(optarg, "-")) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 no_orig = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 strcpy(orig_name, "(zero)");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 if ((orig = fopen(optarg, "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 fprintf(stderr, "%s: unable to open original image file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 strcpy(orig_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 maxlevel = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 if (maxlevel < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 fprintf(stderr, "%s: decomposition level %d out of range\n", progname, maxlevel);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 case 'm':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 m = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 if (m < -1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 fprintf(stderr, "%s: multiplication factor %d out of range\n", progname, m);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 if ((out = fopen(optarg, "wb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 case 'p':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 print_psnr = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 case 'P':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 print_psnr_only = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 case 'q':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 print_psnr = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 print_psnr_subband = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 subband_list = optarg;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 print = print_psnr_only ? out : stderr;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
211 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
218 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
219
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 if (!orig && !no_orig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 fprintf(stderr, "%s: original image file not specified, using zero image\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 strcpy(orig_name, "(zero)");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 no_orig = 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 if (!no_orig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 pgm_readpgminit(orig, &orig_cols, &orig_rows, &orig_maxval, &orig_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 if (in_cols != orig_cols || in_rows != orig_rows) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 fprintf(stderr, "%s: input image %s does not match dimensions of original image %s\n", progname, input_name, orig_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 cols = in_cols;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237 rows = in_rows;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 format = in_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239 maxval = in_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241 input_image = pgm_allocarray(cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242 orig_image = pgm_allocarray(cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244 output = alloc_grays(cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246 if (no_orig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247 for (row = 0; row < rows; row++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248 pgm_readpgmrow(in, input_image[row], cols, maxval, format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249 bzero(orig_image[row], sizeof(gray) * cols);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
251 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
252 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
253 for (row = 0; row < rows; row++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
254 pgm_readpgmrow(in, input_image[row], in_cols, in_maxval, in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
255 pgm_readpgmrow(orig, orig_image[row], orig_cols, orig_maxval, orig_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
256 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
257 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
258
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
259 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
260 if (!no_orig)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
261 fclose(orig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
262
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
263 // complete decomposition
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
264 levels = find_deepest_level(cols, rows) - 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
265 if (!maxlevel) maxlevel = levels;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
266 if (maxlevel > levels) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
267 fprintf(stderr, "%s: decomposition level %d not possible (max. %d), image size is %d x %d\n", progname, maxlevel, levels, cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
268 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
269 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
270
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
271 init_dwt(cols, rows, filter_name, filter, maxlevel, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
272
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
273 input_dwts = fdwt(input_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
274 orig_dwts = fdwt(orig_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
275
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
276 p = input_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
277 q = orig_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
278 min = 10000000.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
279 max = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
280 error = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
281 while (p->coarse && q->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
282 double localmin, localmax, localerror;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
283
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
284 if (subband_in_list(subband_list, HORIZONTAL, p->horizontal->level)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
285 calc_subband(p->horizontal, q->horizontal, HORIZONTAL, &localmin, &localmax, &localerror);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
286 if (m == -1) process_subband_var(output, cols, rows, p->horizontal, q->horizontal, HORIZONTAL, localmin, localmax, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
287 if (localmin < min) min = localmin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
288 if (localmax > max) max = localmax;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
289 error += localerror;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
290 if (print_psnr_subband)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
291 print_subband_psnr(HORIZONTAL, p->horizontal->level, error, p->horizontal->image->width, p->horizontal->image->height, localmin, localmax, print);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
292 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
293 else if (verbose > 5)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
294 fprintf(stderr, "%s: subband %s%d skipped\n", progname, subband_name(HORIZONTAL), p->horizontal->level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
295
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
296 if (subband_in_list(subband_list, VERTICAL, p->vertical->level)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
297 calc_subband(p->vertical, q->vertical, VERTICAL, &localmin, &localmax, &localerror);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
298 if (m == -1) process_subband_var(output, cols, rows, p->vertical, q->vertical, VERTICAL, localmin, localmax, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
299 if (localmin < min) min = localmin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
300 if (localmax > max) max = localmax;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
301 error += localerror;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
302 if (print_psnr_subband)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
303 print_subband_psnr(VERTICAL, p->vertical->level, error, p->vertical->image->width, p->vertical->image->height, localmin, localmax, print);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
304 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
305 else if (verbose > 5)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
306 fprintf(stderr, "%s: subband %s%d skipped\n", progname, subband_name(VERTICAL), p->vertical->level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
307
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
308 if (subband_in_list(subband_list, DIAGONAL, p->diagonal->level)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
309 calc_subband(p->diagonal, q->diagonal, DIAGONAL, &localmin, &localmax, &localerror);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
310 if (m == -1) process_subband_var(output, cols, rows, p->diagonal, q->diagonal, DIAGONAL, localmin, localmax, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
311 if (localmin < min) min = localmin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
312 if (localmax > max) max = localmax;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
313 error += localerror;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
314 if (print_psnr_subband)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
315 print_subband_psnr(DIAGONAL, p->vertical->level, error, p->diagonal->image->width, p->diagonal->image->height, localmin, localmax, print);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
316 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
317 else if (verbose > 5)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
318 fprintf(stderr, "%s: subband %s%d skipped\n", progname, subband_name(DIAGONAL), p->diagonal->level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
319
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
320 p = p->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
321 q = q->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
322
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
323 if (!p->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
324 if (subband_in_list(subband_list, COARSE, p->level)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
325 calc_subband(p, q, COARSE, &localmin, &localmax, &localerror);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
326 if (m == -1) process_subband_var(output, cols, rows, p, q, COARSE, localmin, localmax, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
327 if (localmin < min) min = localmin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
328 if (localmax > max) max = localmax;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
329 error += localerror;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
330 if (print_psnr_subband)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
331 print_subband_psnr(COARSE, p->level, error, p->image->width, p->image->height, localmin, localmax, print);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
332 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
333 else if (verbose > 5)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
334 fprintf(stderr, "%s: subband %s%d skipped\n", progname, subband_name(COARSE), p->level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
335 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
336 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
337
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
338 p = input_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
339 q = orig_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
340 while (p->coarse && q->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
341 if (m > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
342 process_subband_fixed(output, cols, rows, p->horizontal, q->horizontal, HORIZONTAL, m);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
343 process_subband_fixed(output, cols, rows, p->vertical, q->vertical, VERTICAL, m);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
344 process_subband_fixed(output, cols, rows, p->diagonal, q->diagonal, DIAGONAL, m);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
345 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
346 else if (m == 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
347 process_subband_var(output, cols, rows, p->horizontal, q->horizontal, HORIZONTAL, min, max, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
348 process_subband_var(output, cols, rows, p->vertical, q->vertical, VERTICAL, min, max, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
349 process_subband_var(output, cols, rows, p->diagonal, q->diagonal, DIAGONAL, min, max, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
350 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
351
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
352 p = p->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
353 q = q->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
354
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
355 if (!p->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
356 if (m > 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
357 process_subband_fixed(output, cols, rows, p, q, COARSE, m);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
358 else if (m == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
359 process_subband_var(output, cols, rows, p, q, COARSE, min, max, maxval);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
360 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
361 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
362
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
363 if (!print_psnr_only) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
364 pgm_writepgminit(out, cols, rows, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
365 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
366 pgm_writepgmrow(out, output[row], cols, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
367
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
368 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
369 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
370
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
371 pgm_freearray(input_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
372 pgm_freearray(orig_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
373 free_grays(output);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
374
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
375 if (print_psnr || print_psnr_only) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
376 double mse = error / (double) (cols * rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
377 double rmse = sqrt(mse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
378 double psnr = 20.0 * log(255.0 / rmse) / log(10.0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
379 if (mse > 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
380 fprintf(print, "PSNR: %lf dB\n", psnr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
381 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
382 fprintf(print, "PSNR: inf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
383 fprintf(print, "RMS: %lf\n", rmse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
384 fprintf(print, "MSE: %lf\n", mse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
385 fprintf(print, "dmin, dmax: %lf, %lf\n", min, max);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
386 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
387
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
388 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
389 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.