annotate Meerwald/cmp_dwt.c @ 1:647ab0f05aae v0.4

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

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