annotate Meerwald/wm_dugad_e.c @ 22:d8551fb39a5e default tip

Added tag v0.6 for changeset 1c4ccd635a68
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:57:51 +0100
parents 4987db85cfae
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 "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 file] [-h] [-l n] [-o file] [-t n] [-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-l n\t\tdecomposition levels\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 fprintf(stderr, "\t-t n\t\tcasting threshold\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 // actual watermarking procedure: embeds a watermark of n normally
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 // distributed values into a coefficients > threshold t1 of a subband
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 void wm_subband(Image s, double *w, int n, double a, double t1) {
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 for (i = 0; i < s->width * s->height; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 if (fabs(s->data[i]) > t1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 s->data[i] += (a * fabs(s->data[i]) * w[i % n]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 char signature_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 i, c;
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
43 int row;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 int n;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 double alpha = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 double t1 = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
50 int level = 0;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 int filter = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 int method = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 char filter_name[MAXPATHLEN] = "";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 gray **image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 Image_tree dwts, s;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 gray maxval;
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
61 int rows, cols, format;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 double *watermark;
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_init();
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:e:f:F:h?l:o:s:t: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 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 method = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 if (method < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
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 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 filter = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 if (filter <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
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 strcpy(filter_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 case 'l':
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
100 level = atoi(optarg);
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
101 if (level <= 0) {
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
102 fprintf(stderr, "%s: decomposition level %d out of range\n", progname, level);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 if ((out = fopen(optarg, "wb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 fprintf(stderr, "%s: unable to open output 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(output_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 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 case 't':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 t1 = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 if (t1 <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 fprintf(stderr, "%s: casting threshold %f out of range\n", progname, t1);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
145 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
152 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
153
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 if (strspn(line, "DGSG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 fscanf(sig, "%d\n", &n);
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
159 if (level == 0)
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
160 fscanf(sig, "%d\n", &level);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 if (alpha == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 fscanf(sig, "%lf\n", &alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
166 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 if (t1 == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 fscanf(sig, "%lf\n", &t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
170 fscanf(sig, "%*f\n");
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
171 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 if (method < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 fscanf(sig, "%d\n", &method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 if (filter == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 fscanf(sig, "%d\n", &filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 if (!strcmp(filter_name, ""))
15
ad1d224896c5 fix scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
181 fscanf(sig, "%[^\n\r]\n", filter_name);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 exit(1);
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 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 watermark = malloc(n * sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 for (i = 0; i < n; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 fscanf(sig, "%lf\n", &watermark[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 pgm_readpgminit(in, &cols, &rows, &maxval, &format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 image = pgm_allocarray(cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 pgm_readpgmrow(in, image[row], cols, maxval, format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 // wavelet transform
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
210 init_dwt(cols, rows, filter_name, filter, level, method);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 #ifdef POLLEN_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
212 #include "pollen_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 #ifdef PARAM_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
215 #include "param_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 dwts = fdwt(image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 // embed watermark in all subbands of a decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 for (i = 0, s = dwts; i < 3; i++, s = s->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 wm_subband(s->horizontal->image, watermark, n, alpha, t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 wm_subband(s->vertical->image, watermark, n, alpha, t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 wm_subband(s->diagonal->image, watermark, n, alpha, t1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 free(watermark);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 idwt(dwts, image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 pgm_writepgminit(out, cols, rows, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 pgm_writepgmrow(out, image[row], cols, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 pgm_freearray(image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241 }

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