annotate Meerwald/wm_wang_d.c @ 4:9cf6ec970448 v0.5

mention filter param.
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 21:13:11 +0200
parents acb6967ee76d
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 "wang_common.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 #include "pgm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 char *progname;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 void usage(void) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 fprintf(stderr, "usage: %s [-a n] [-b n] [-e n] [-f n] [-F file] [-h] [-n n] [-o file] [-v n] -s file -i file file\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 fprintf(stderr, "\t-a n\t\talpha factor\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-b n\t\tbeta factor\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 fprintf(stderr, "\t-f n\t\tfilter number\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-F file\t\tfilter definition file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-h\t\tprint usage\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-i file\t\toriginal image file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-n n\t\twatermark length\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-o file\t\tfile for extracted watermark\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 fprintf(stderr, "\t-s file\t\toriginal signature file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 fprintf(stderr, "\t-v n\t\tverbosity level\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 FILE *orig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 gray **input_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 gray **orig_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 char orig_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 int c, w;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 int n = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 int method = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 int filter = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 char filter_name[MAXPATHLEN] = "";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
47 int level = 0;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 double alpha = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 double beta = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 int in_rows, in_cols, in_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 gray in_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 int orig_rows, orig_cols, orig_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 gray orig_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 int rows, cols;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 int row, col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 double *watermark;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 Image_tree input_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 Image_tree orig_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 pgm_init(&argc, argv); wm_init2();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 while ((c = getopt(argc, argv, "a:b:e:f:F:h?i:n:o:s:v:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 alpha = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 if (alpha <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 case 'b':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 beta = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 if (beta <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 fprintf(stderr, "%s: beta factor %f out of range\n", progname, alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 case 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 method = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 if (method < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 case 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 filter = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 if (filter <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 case 'F':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 strcpy(filter_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 case 'i':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 if ((orig = fopen(optarg, "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 fprintf(stderr, "%s: unable to open original image file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 strcpy(orig_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 'n':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 n = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 if (n < 1 || n > 32000) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 if ((out = fopen(optarg, "w")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
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 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 usage();
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 if (argc == 1 && *argv[0] != '-')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 strcpy(input_name, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 if (!orig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 fprintf(stderr, "%s: original image file not specified, use -i file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 if (strspn(line, "WGSG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 if (alpha == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 fscanf(sig, "%lf\n", &alpha);
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, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 if (beta == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 fscanf(sig, "%lf\n", &beta);
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, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 if (method < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 fscanf(sig, "%d\n", &method);
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, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 if (filter == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 fscanf(sig, "%d\n", &filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 if (!strcmp(filter_name, ""))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 fscanf(sig, "%[^\n\r]\n", &filter_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 exit(1);
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 watermark = malloc(n * sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 pgm_readpgminit(orig, &orig_cols, &orig_rows, &orig_maxval, &orig_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 if (in_cols != orig_cols || in_rows != orig_rows) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 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
209 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 cols = in_cols;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 rows = in_rows;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 input_image = pgm_allocarray(in_cols, in_rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 orig_image = pgm_allocarray(orig_cols, orig_rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 for (row = 0; row < in_rows; row++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 pgm_readpgmrow(in, input_image[row], in_cols, in_maxval, in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 pgm_readpgmrow(orig, orig_image[row], orig_cols, orig_maxval, orig_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 fclose(orig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 // complete decomposition
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
228 level = find_deepest_level(cols, rows) - 1;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
230 init_dwt(cols, rows, filter_name, filter, level, method);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 #ifdef POLLEN_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
232 #include "pollen_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 #ifdef PARAM_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
235 #include "param_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 input_dwts = fdwt(input_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239 orig_dwts = fdwt(orig_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241 // build tree for subband selection, calculate subband thresholds
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242 init_subbands(orig_dwts);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 set_subbands_type_beta(HORIZONTAL, beta);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244 set_subbands_type_beta(VERTICAL, beta);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245 calc_subbands_threshold();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247 fprintf(out, "WGWM\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248 fprintf(out, "%d\n", n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250 w = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
251 while (w < n) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
252 Subband_data s;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
253
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
254 // select subband with max. threshold
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
255 s = select_subband();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
256 if (verbose > 1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
257 fprintf(stderr, "%s: selected subband %s%d, T=%lf, beta=%lf\n", progname, subband_name(s->type), s->level, s->T, s->beta);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
258
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
259 // watermark significant coefficients and set them selected
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
260 // check is entire signature has been embedded
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
261 c = select_subband_coeff(s);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
262 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
263 Pixel p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
264 Pixel q;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
265 if (c < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
266 // no more significant coefficients in subband
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
267 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
268
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
269 p = get_subband_coeff(s, c);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
270 if (p < s->Cmax) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
271 q = get_dwt_coeff(input_dwts, s->level, s->type, c);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
272 watermark[w] = (q - p) / (alpha * s->beta * s->T);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
273 fprintf(out, "%lf\n", watermark[w]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
274
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
275 if (verbose > 2)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
276 fprintf(stderr, "%s: detected sig. coeff. #%d (= %lf)\n from %s%d coeff. #%d\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
277 progname, w, watermark[w], subband_name(s->type), s->level, c);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
278
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
279 w++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
280 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
281 mark_subband_coeff(s, c);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
282
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
283 // select next significant coefficient
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
284 c = select_subband_coeff_from(s, c);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
285 } while (w < n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
286
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
287 // update subband threshold
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
288 s->T /= 2.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
289
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
290 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
291
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
292 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
293
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
294 free_subbands();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
295
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
296 free(watermark);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
297
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
298 pgm_freearray(input_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
299 pgm_freearray(orig_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
300
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
301 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
302 }

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