annotate Meerwald/wm_xia_e.c @ 3:acb6967ee76d

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

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