annotate Meerwald/wm_corvi_e.c @ 8:f83ef905a63d

fixing many warnings increase capacity for coordinates in bruyn fix some uninit. variables
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 22 Apr 2008 13:36:05 +0200
parents acb6967ee76d
children ad1d224896c5
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 "pgm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 char *progname;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 void usage(void) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 fprintf(stderr, "usage: %s [-a n] [-e n] [-f n] [-F n] [-h] [-o file] [-v n] -s file file\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 fprintf(stderr, "\t-a n\t\talpha factor/embedding strength\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-f n\t\tfilter number\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-F file\t\tfilter definition file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-v n\t\tverbosity level\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 int row, col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int n;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 double alpha = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 int filter = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 int method = -1;
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
39 int level = 0;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 char filter_name[MAXPATHLEN] = "";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 gray **image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 Image_tree dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 gray maxval;
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
48 int rows, cols, format;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 pgm_init(&argc, argv); wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 while ((c = getopt(argc, argv, "a:e:f:F:h?o:s:v:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 alpha = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 if (alpha <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 case 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 method = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 if (method < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 case 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 filter = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 if (filter <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 case 'F':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 strcpy(filter_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 if ((out = fopen(optarg, "wb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
116 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
123 }
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 if (strspn(line, "CVSG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 if (alpha == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 fscanf(sig, "%lf\n", &alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 if (method < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 fscanf(sig, "%d\n", &method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 fscanf(sig, "%*d\n");
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 fscanf(sig, "%d\n", &filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 if (!strcmp(filter_name, ""))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 fscanf(sig, "%[^\n\r]\n", &filter_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
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
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 pgm_readpgminit(in, &cols, &rows, &maxval, &format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 image = pgm_allocarray(cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 pgm_readpgmrow(in, image[row], cols, maxval, format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 level = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 row = rows;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 col = cols;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 while (n < row * col / 4.0 && row >= 2 && col >= 2) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 row /= 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 col /= 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 level++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 if (verbose >= 2) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 fprintf(stderr, "%s: embedding into coarse image (x %d/y %d) at level %d\n", progname, col, row, level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 init_dwt(cols, rows, filter_name, filter, level, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 #ifdef POLLEN_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
181 #include "pollen_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 #ifdef PARAM_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
184 #include "param_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 dwts = fdwt(image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 Image_tree p = dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 double med;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 while (!p->image)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 p = p->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 img = p->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 med = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 for (row = 0; row < img->height; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 for (col = 0; col < img->width; col++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 med += get_pixel(img, col, row);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 med /= (double) (img->height * img->width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 row = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 col = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 while (n > 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 double pix;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 double g;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 fscanf(sig, "%lf\n", &g);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 pix = get_pixel(img, col, row);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 pix = med + (pix - med) * (1.0 + alpha * g);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 set_pixel(img, col, row, pix);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 if (++col == img->width) { col = 0; row++; }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 n--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 idwt(dwts, image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 pgm_writepgminit(out, cols, rows, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 pgm_writepgmrow(out, image[row], cols, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 pgm_freearray(image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237 }

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