annotate Meerwald-dir/wm_dugad_d.c @ 25:5a57a145bccb default tip

Added tag v0.7 for changeset 9f20bce6184e
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Fri, 20 Dec 2024 13:32:15 +0100
parents 9f20bce6184e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "dwt.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 #include "dwt_util.h"
24
9f20bce6184e move directories, support netpbm 11
Peter Meerwald-Stadler <pmeerw@pmeerw.net>
parents: 16
diff changeset
4 #include "netpbm/pgm.h"
0
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 file] [-h] [-l n] [-n n] [-o file] [-v n] [-t 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\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 levels\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-n n\t\twatermark length\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-o file\t\tfile for extracted watermark\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-s file\t\toriginal signature file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-t n\t\tdetection threshold\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 fprintf(stderr, "\t-v n\t\tverbosity level\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 void wm_subband(Image s, double *w, int n, double t2, int *m, double *z, double *v) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 *m = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 *z = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 *v = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 for (i = 0; i < s->width * s->height; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 if (s->data[i] > t2) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 (*z) += (s->data[i] * w[i % n]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 (*v) += fabs(s->data[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 (*m)++;
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 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 gray **input_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
50 int c;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 int n = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 int method = -1;
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
54 int level = 0;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 int filter = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 char filter_name[MAXPATHLEN] = "";
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 double t2 = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 int in_rows, in_cols, in_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 gray in_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 int rows, cols;
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
64 int row;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 double *watermark;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 Image_tree dwts, s;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 pgm_init(&argc, argv); wm_init2();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 while ((c = getopt(argc, argv, "a:e:f:F:h?l:n:o:s:v:t")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 alpha = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 if (alpha <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 fprintf(stderr, "%s: alpha 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 'l':
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
107 level = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
108 if (level <= 0) {
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
109 fprintf(stderr, "%s: decomposition level %d out of range\n", progname, level);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 case 'n':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 n = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 if (n < 1 || n > 32000) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 if ((out = fopen(optarg, "w")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 case 't':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 t2 = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 if (t2 <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 fprintf(stderr, "%s: detection threshold %f out of range\n", progname, t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 }
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 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
160 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
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 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
167 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
168
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 if (strspn(line, "DGSG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 fscanf(sig, "%d\n", &n);
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
174 if (level == 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
175 fscanf(sig, "%d\n", &level);
0
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 (alpha == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 fscanf(sig, "%lf\n", &alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
181 fscanf(sig, "%*f\n");
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
182 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 if (t2 == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 fscanf(sig, "%lf\n", &t2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
186 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 if (method < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 fscanf(sig, "%d\n", &method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 if (filter == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 fscanf(sig, "%d\n", &filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 if (!strcmp(filter_name, ""))
15
ad1d224896c5 fix scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
196 fscanf(sig, "%[^\n\r]\n", filter_name);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 watermark = malloc(n * sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 for (i = 0; i < n; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 fscanf(sig, "%lf\n", &watermark[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 cols = in_cols;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 rows = in_rows;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 input_image = pgm_allocarray(in_cols, in_rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 for (row = 0; row < in_rows; row++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 pgm_readpgmrow(in, input_image[row], in_cols, in_maxval, in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
228 init_dwt(cols, rows, filter_name, filter, level, method);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 #ifdef POLLEN_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
230 #include "pollen_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 #ifdef PARAM_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
233 #include "param_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 dwts = fdwt(input_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 fprintf(out, "DGWM\n");
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
239 fprintf(out, "%d\n", level);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240 fprintf(out, "%f\n", alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
242 for (i = 0, s = dwts; i < level; i++, s = s->coarse) {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 int m;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244 double z, v;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246 wm_subband(s->horizontal->image, watermark, n, t2, &m, &z, &v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247 fprintf(out, "%d %f %f\n", m, z, v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248 wm_subband(s->vertical->image, watermark, n, t2, &m, &z, &v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249 fprintf(out, "%d %f %f\n", m, z, v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250 wm_subband(s->diagonal->image, watermark, n, t2, &m, &z, &v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
251 fprintf(out, "%d %f %f\n", m, z, v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
252 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
253
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
254 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
255
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
256 free(watermark);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
257
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
258 pgm_freearray(input_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
259
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
260 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
261 }

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