annotate Meerwald/wm_kim_a.c @ 23:71dd4b96221b

fix some compiler warning
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Fri, 20 Dec 2024 12:53:41 +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 "wm_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 #include "kim_common.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] [-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
11 fprintf(stderr, "\t-a n\t\talpha factor/embedding strength for detail subbands\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-a n\t\talpha factor/embedding strength for approximation subband\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-l n\t\tdecomposition level\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 fprintf(stderr, "\t-s file\t\tsignature to embed in input image\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 int mark_subband(Image_tree s, int name, double alpha, double watermark[], double threshold, int w, int n, int verbose) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 int i, j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 double last = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 for (i = 5; i < s->image->height-5; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 for (j = 5; j < s->image->width-5; j++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 double coeff, newcoeff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 coeff = get_pixel(s->image, i, j);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 if (fabs(coeff) > threshold / 1.5 ) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 newcoeff = coeff - coeff * alpha * watermark[w++ % n];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 set_pixel(s->image, i, j, newcoeff);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 fprintf(stderr, "%s: (%d/%d) %f: %f -> %f; a=%f\n", progname, j, i, watermark[w % n], coeff, newcoeff, alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 w++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 if (verbose > 5)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 fprintf(stderr, "%s: watermarking %s%d, size %d x %d; embedded %d coeffs. total\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 progname, subband_name(name), s->level, s->image->width, s->image->height, w);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 return w;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 int i, c, w;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 int row, col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 int n;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 double alpha_detail = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 double alpha_approx = 0.0;
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
66 int level = 0;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 int filter = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 int method = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 int levels;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 char filter_name[MAXPATHLEN] = "";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 gray **image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 Image_tree p, dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 gray maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 int rows, cols, colors, format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 double *watermark;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 pgm_init(&argc, argv);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 #ifdef __EMX__
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 _fsetmode(in, "b");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 _fsetmode(out, "b");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 while ((c = getopt(argc, argv, "a:A:e:f:F:h?o:l:s:v:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 alpha_detail = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 if (alpha_detail <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha_detail);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 case 'A':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 alpha_approx = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 if (alpha_approx <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha_approx);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 level = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 if (level <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 fprintf(stderr, "%s: decomposition level %d out of range\n", progname, level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 case 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 method = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 if (method < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 case 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 filter = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 if (filter <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 case 'F':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 strcpy(filter_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 if ((out = fopen(optarg, "wb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
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 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
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 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 if (argc == 1 && *argv[0] != '-')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 strcpy(input_name, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 if (strspn(line, "KISG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 if (alpha_detail == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 fscanf(sig, "%lf\n", &alpha_detail);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
184 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 if (alpha_approx == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 fscanf(sig, "%lf\n", &alpha_approx);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 else
16
4987db85cfae fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 15
diff changeset
188 fscanf(sig, "%*f\n");
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 if (level == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 fscanf(sig, "%d\n", &level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 if (method < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 fscanf(sig, "%d\n", &method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 if (filter == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 fscanf(sig, "%d\n", &filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 if (!strcmp(filter_name, ""))
15
ad1d224896c5 fix scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
202 fscanf(sig, "%[^\n\r]\n", filter_name);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
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 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 watermark = malloc(n * sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 for (i = 0; i < n; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 fscanf(sig, "%lf\n", &watermark[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 pgm_readpgminit(in, &cols, &rows, &maxval, &format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 image = pgm_allocarray(cols, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 pgm_readpgmrow(in, image[row], cols, maxval, format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 // complete decomposition
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 levels = find_deepest_level(cols, rows) - 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 if (level > levels) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 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
231 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 // wavelet transform
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235 init_dwt(cols, rows, filter_name, filter, level, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 #ifdef POLLEN_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
237 #include "pollen_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239 #ifdef PARAM_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
240 #include "param_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 dwts = fdwt(image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245 p = dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246 w = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248 // process each decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249 while (p->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250 int current_level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
251 double threshold;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
252 double max_coeff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
253 double alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
254
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
255 // get current decomposition level number
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
256 current_level = p->horizontal->level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
257
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
258 // find largest absolute coefficient in detail subbands of current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
259 max_coeff = find_level_largest_coeff(p, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
260
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
261 // calculate significance threshold for current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
262 threshold = calc_level_threshold(max_coeff, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
263
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
264 // calculate embedding strength alpha for current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
265 alpha = calc_level_alpha_detail(alpha_detail, level, current_level, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
266
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
267 if (verbose > 1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
268 fprintf(stderr, "%s: level %d, threshold %f, alpha %f\n", progname, current_level, threshold, alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
269
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
270 // embed watermark sequence into detail subbands of current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
271 w = mark_subband(p->horizontal, HORIZONTAL, alpha, watermark, threshold, w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
272 w = mark_subband(p->vertical, VERTICAL, alpha, watermark, threshold, w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
273 w = mark_subband(p->diagonal, DIAGONAL, alpha, watermark, threshold, w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
274
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
275 p = p->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
276 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
277
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
278 // mark approximation image using calculated significance threshold and embedding strength
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
279 w = mark_subband(p, COARSE, alpha_approx, watermark, calc_level_threshold(find_subband_largest_coeff(p, COARSE, verbose), verbose), w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
280
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
281 free(watermark);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
282 idwt(dwts, image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
283
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
284 pgm_writepgminit(out, cols, rows, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
285 for (row = 0; row < rows; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
286 pgm_writepgmrow(out, image[row], cols, maxval, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
287 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
288
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
289 pgm_freearray(image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
290
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
291 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
292 }

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