annotate Meerwald/wm_kim_d.c @ 15:ad1d224896c5

fix scanf() warning
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Mon, 30 Jun 2008 20:59:01 +0200
parents f83ef905a63d
children 4987db85cfae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "dwt.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 #include "pgm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 #include "dwt_util.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 #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 file] [-h] [-l 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 for detail subband\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 fprintf(stderr, "\t-A n\t\talpha factor for approximation image\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-l n\t\tdecomposition level\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 extract_subband(Image_tree s, Image_tree t, int name, double alpha, double watermark[], double threshold, int w, int n, int verbose) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 int i, j;
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 orig_coeff, input_coeff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 orig_coeff = get_pixel(s->image, i, j);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 input_coeff = get_pixel(t->image, i, j);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 if (fabs(orig_coeff) > threshold) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 watermark[w++] = (input_coeff - orig_coeff) / (alpha * orig_coeff);
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
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 if (verbose > 5)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 fprintf(stderr, "%s: extracted %s%d, size %d x %d; %d coeffs. total\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 progname, subband_name(name), s->level, s->image->width, s->image->height, w);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 return w;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 void write_mark(FILE *out, double watermark[], int n) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 fprintf(out, "%d\n", n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 for (i = 0; i < n; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 fprintf(out, "%f\n", watermark[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 int main(int argc, char *argv[]) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 FILE *in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 FILE *out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 FILE *orig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 FILE *sig = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 gray **input_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 gray **orig_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 char signature_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 char output_name[MAXPATHLEN] = "(stdout)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 char input_name[MAXPATHLEN] = "(stdin)";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 char orig_name[MAXPATHLEN];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 int c, w;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 int n = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 int method = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 int filter = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 char filter_name[MAXPATHLEN] = "";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 int level = 0, levels;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 double alpha_detail = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 double alpha_approx = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 int in_rows, in_cols, in_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 gray in_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 int orig_rows, orig_cols, orig_format;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 gray orig_maxval;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 int rows, cols;
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
84 int row;
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 double *watermark;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 Image_tree input_dwts, orig_dwts, p, q;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 int verbose = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 progname = argv[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 pgm_init(&argc, argv); wm_init2();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 while ((c = getopt(argc, argv, "a:A:e:f:F:h?i:l:o:s:v:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 alpha_detail = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 if (alpha_detail <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha_detail);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 case 'A':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 alpha_approx = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 if (alpha_approx <= 0.0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha_approx);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 case 'e':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 method = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 if (method < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 case 'f':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 filter = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 if (filter <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 case 'F':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 strcpy(filter_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 case 'h':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 case '?':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 case 'i':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 if ((orig = fopen(optarg, "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 fprintf(stderr, "%s: unable to open original image file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 strcpy(orig_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 level = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 if (level <= 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 fprintf(stderr, "%s: decomposition level %d out of range\n", progname, level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 case 'o':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 if ((out = fopen(optarg, "w")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 strcpy(output_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 if ((sig = fopen(optarg, "r")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
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 strcpy(signature_name, optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 case 'v':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 verbose = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 if (verbose < 0) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
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 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 if (argc > 1) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 usage();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
179 if (argc == 1 && *argv[0] != '-') {
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 if ((in = fopen(argv[0], "rb")) == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 strcpy(input_name, argv[0]);
8
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
186 }
f83ef905a63d fixing many warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 3
diff changeset
187
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 if (!orig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 fprintf(stderr, "%s: original image file not specified, use -i file option\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 if (sig) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 char line[32];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 fgets(line, sizeof(line), sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 if (strspn(line, "KISG") >= 4) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 fscanf(sig, "%d\n", &n);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 if (alpha_detail == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 fscanf(sig, "%lf\n", &alpha_detail);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 if (alpha_approx == 0.0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 fscanf(sig, "%lf\n", &alpha_approx);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 fscanf(sig, "%*lf\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 if (level == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 fscanf(sig, "%d\n", &level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 if (method < 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 fscanf(sig, "%d\n", &method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 if (filter == 0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 fscanf(sig, "%d\n", &filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 fscanf(sig, "%*d\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 if (!strcmp(filter_name, ""))
15
ad1d224896c5 fix scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 8
diff changeset
219 fscanf(sig, "%[^\n\r]\n", filter_name);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 fscanf(sig, "%*[^\n\r]\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 fclose(sig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
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 pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235 pgm_readpgminit(orig, &orig_cols, &orig_rows, &orig_maxval, &orig_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237 if (in_cols != orig_cols || in_rows != orig_rows) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 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
239 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242 cols = in_cols;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 rows = in_rows;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245 input_image = pgm_allocarray(in_cols, in_rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246 orig_image = pgm_allocarray(orig_cols, orig_rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248 for (row = 0; row < in_rows; row++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249 pgm_readpgmrow(in, input_image[row], in_cols, in_maxval, in_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250 pgm_readpgmrow(orig, orig_image[row], orig_cols, orig_maxval, orig_format);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
251 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
252
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
253 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
254 fclose(orig);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
255
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
256 // complete decomposition
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
257 levels = find_deepest_level(cols, rows) - 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
258 if (level > levels) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
259 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
260 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
261 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
262
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
263 init_dwt(cols, rows, filter_name, filter, level, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
264 #ifdef POLLEN_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
265 #include "pollen_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
266 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
267 #ifdef PARAM_STUFF
3
acb6967ee76d update to 0.5
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
268 #include "param_stuff.c"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
269 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
270
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
271 input_dwts = fdwt(input_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
272 orig_dwts = fdwt(orig_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
273
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
274 watermark = malloc((rows * cols) * sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
275 if (!watermark) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
276 fprintf(stderr, "%s: malloc() failed\n\n", progname);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
277 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
278 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
279
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
280 p = input_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
281 q = orig_dwts;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
282 w = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
283 while (p->coarse && q->coarse) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
284 int current_level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
285 double threshold;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
286 double max_coeff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
287 double alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
288
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
289 // get current decomposition level number
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
290 current_level = q->horizontal->level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
291
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
292 // find largest absolute coefficient in detail subbands of current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
293 max_coeff = find_level_largest_coeff(q, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
294
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
295 // calculate significance threshold for current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
296 threshold = calc_level_threshold(max_coeff, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
297
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
298 // calculate embedding strength alpha for current decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
299 alpha = calc_level_alpha_detail(alpha_detail, level, current_level, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
300
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
301 if (verbose > 1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
302 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
303
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
304 w = extract_subband(q->horizontal, p->horizontal, HORIZONTAL, alpha, watermark, threshold, w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
305 w = extract_subband(q->vertical, p->vertical, VERTICAL, alpha, watermark, threshold, w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
306 w = extract_subband(q->diagonal, p->diagonal, DIAGONAL, alpha, watermark, threshold, w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
307
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
308 p = p->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
309 q = q->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
310 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
311
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
312 // extract watermark from approximation image using calculated significance threshold and embedding strength
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
313 w = extract_subband(q, p, COARSE, alpha_approx, watermark, calc_level_threshold(find_subband_largest_coeff(q, COARSE, verbose), verbose), w, n, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
314
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
315 fprintf(out, "KIWM\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
316 write_mark(out, watermark, w);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
317
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
318 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
319
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
320 free(watermark);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
321
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
322 pgm_freearray(input_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
323 pgm_freearray(orig_image, rows);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
324
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
325 exit(0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
326 }

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