0
|
1 /* Watermarking program - Subband DCT Transform based */
|
|
2 /* Module : Testing */
|
|
3 /* Author : Vassilis Fotopoulos */
|
|
4 /* Date : 25/4/2000 */
|
|
5 /* Revision : 6.0 */
|
|
6 /* Developed at : ELLAB */
|
|
7 /* Electronics Laboratory */
|
|
8 /* Department of Physics */
|
|
9 /* University of Patras - GREECE */
|
|
10 /* Copyleft (c) 1999 */
|
|
11 /*------------------------------------------------------*/
|
|
12 /* pseudorandom noise generator's code is */
|
|
13 /* taken from "Numerical Recipes in C" */
|
|
14 /* FCT implementation from University of Bath */
|
|
15 /*------------------------------------------------------*/
|
|
16 #include <stdio.h>
|
|
17 #include <stdlib.h>
|
|
18 #include <string.h>
|
|
19 #include <math.h>
|
|
20 #include <float.h>
|
|
21 #include <getopt.h>
|
|
22 #include "common.h"
|
|
23
|
|
24 //--------------------------------------------------------
|
|
25 void add_hor_add_ver(double **in, int N, double **out);
|
|
26 void add_hor_sub_ver(double **in, int N, double **out);
|
|
27 void sub_hor_add_ver(double **in, int N, double **out);
|
|
28 void sub_hor_sub_ver(double **in, int N, double **out);
|
|
29 double detect_mark(double *i, int N, long key, long int L, long int M, double a);
|
|
30
|
|
31 //--------------------------------------------------------
|
|
32 double cu[1024];
|
|
33 double cv[1024];
|
|
34 int height, width;
|
|
35 //--------------------------------------------------------
|
|
36 void add_hor_add_ver(double **in, int N, double **out)
|
|
37 {
|
|
38 double **temp;
|
|
39 int r, c;
|
|
40 temp = dmatrix(N, N);
|
|
41 for (r = 0; r < N; r++)
|
|
42 for (c = 0; c < N / 2; c++)
|
|
43 temp[r][c] = (in[r][2 * c] + in[r][2 * c + 1]) / 2;
|
|
44 for (c = 0; c < N / 2; c++)
|
|
45 for (r = 0; r < N / 2; r++)
|
|
46 out[r][c] = (temp[2 * r][c] + temp[2 * r + 1][c]) / 2;
|
|
47 freematrix_d(temp, N);
|
|
48 }
|
|
49 //--------------------------------------------------------
|
|
50 void add_hor_sub_ver(double **in, int N, double **out)
|
|
51 {
|
|
52 double **temp;
|
|
53 int r, c;
|
|
54 temp = dmatrix(N, N);
|
|
55 for (r = 0; r < N; r++)
|
|
56 for (c = 0; c < N / 2; c++)
|
|
57 temp[r][c] = (in[r][2 * c] + in[r][2 * c + 1]) / 2;
|
|
58 for (c = 0; c < N / 2; c++)
|
|
59 for (r = 0; r < N / 2; r++)
|
|
60 out[r][c] = (temp[2 * r][c] - temp[2 * r + 1][c]) / 2;
|
|
61 freematrix_d(temp, N);
|
|
62 }
|
|
63 //--------------------------------------------------------
|
|
64 void sub_hor_add_ver(double **in, int N, double **out)
|
|
65 {
|
|
66 double **temp;
|
|
67 int r, c;
|
|
68 temp = dmatrix(N, N);
|
|
69 for (r = 0; r < N; r++)
|
|
70 for (c = 0; c < N / 2; c++)
|
|
71 temp[r][c] = (in[r][2 * c] - in[r][2 * c + 1]) / 2;
|
|
72 for (c = 0; c < N / 2; c++)
|
|
73 for (r = 0; r < N / 2; r++)
|
|
74 out[r][c] = (temp[2 * r][c] + temp[2 * r + 1][c]) / 2;
|
|
75 freematrix_d(temp, N);
|
|
76 }
|
|
77 //--------------------------------------------------------
|
|
78 void sub_hor_sub_ver(double **in, int N, double **out)
|
|
79 {
|
|
80 double **temp;
|
|
81 int r, c;
|
|
82 temp = dmatrix(N, N);
|
|
83 for (r = 0; r < N; r++)
|
|
84 for (c = 0; c < N / 2; c++)
|
|
85 temp[r][c] = (in[r][2 * c] - in[r][2 * c + 1]) / 2;
|
|
86 for (c = 0; c < N / 2; c++)
|
|
87 for (r = 0; r < N / 2; r++)
|
|
88 out[r][c] = (temp[2 * r][c] - temp[2 * r + 1][c]) / 2;
|
|
89 freematrix_d(temp, N);
|
|
90 }
|
|
91
|
|
92 //---------------------------------------------------------
|
|
93 double detect_mark(double *i, int N, long key, long int L, long int M, double a)
|
|
94 {
|
|
95 int row, col, count;
|
|
96 long int elem, temp, seed;
|
|
97 double z;
|
|
98
|
|
99
|
|
100 seed = key;
|
|
101 z = 0.0;
|
|
102 count = 0;
|
|
103 elem = 0;
|
|
104 row = 2;
|
|
105 col = -1;
|
|
106 do {
|
|
107 do {
|
|
108 row--;
|
|
109 col++;
|
|
110 elem++;
|
|
111 if (col < N) {
|
|
112 if (elem > M) {
|
|
113 temp = row * N + col;
|
|
114 z += i[temp] * gasdev(&seed);
|
|
115 count++;
|
|
116 }
|
|
117 }
|
|
118 } while (row > 0);
|
|
119 row = 2 + col;
|
|
120 col = -1;
|
|
121 } while (count < L);
|
|
122
|
|
123 return (z / L);
|
|
124 }
|
|
125
|
|
126 int main(int argc, char* argv[])
|
|
127 {
|
|
128 double **i;
|
|
129 FILE *in;
|
|
130 int N;
|
|
131 long int key, M1, L1, M2, L2;
|
|
132 double **ll, **lh, **hl, **hh;
|
|
133 double *v1, *v2, *v3, *v99;
|
|
134 double m1, m2, m3, detect_value, m99;
|
|
135 int ** image_i;
|
|
136 int c;
|
|
137 int wm_length_1 = 10000, wm_length_ll = 10000, coeff_start_1 = 3000, coeff_start_ll = 3000;
|
|
138 double a_ll = 0.1, a_other = 0.2;
|
|
139
|
|
140 pgm_init(&argc, argv); wm_init2();
|
|
141
|
|
142 while ((c = getopt(argc, argv, "a:b:t:m:s:l:")) != EOF) {
|
|
143 switch (c) {
|
|
144 case 'a':
|
|
145 a_ll = atof(optarg);
|
|
146 break;
|
|
147 case 'b':
|
|
148 a_other = atof(optarg);
|
|
149 break;
|
|
150 case 't':
|
|
151 coeff_start_1 = atoi(optarg);
|
|
152 break;
|
|
153 case 'm':
|
|
154 wm_length_1 = atoi(optarg);
|
|
155 break;
|
|
156 case 's':
|
|
157 coeff_start_ll = atoi(optarg);
|
|
158 break;
|
|
159 case 'l':
|
|
160 wm_length_ll = atoi(optarg);
|
|
161 break;
|
|
162 }
|
|
163 }
|
|
164 argc -= optind;
|
|
165 argv += optind;
|
|
166
|
|
167 in = stdin;
|
|
168 open_image(in, &width, &height);
|
|
169 image_i = imatrix(height, width);
|
|
170 load_image(image_i, in, width, height);
|
|
171
|
|
172 if (height == width)
|
|
173 N = height;
|
|
174 else {
|
|
175 fprintf(stderr, "Cannot Proccess non-square images!\n");
|
|
176 exit( -11);
|
|
177 }
|
|
178 // starting coeff. for 1st level decomp.
|
|
179 M1 = coeff_start_1;
|
|
180 // number of coeffs to alter
|
|
181 L1 = wm_length_1;
|
|
182 // alpha parameter
|
|
183
|
|
184 // now the LL band
|
|
185 M2 = coeff_start_ll;
|
|
186 L2 = wm_length_ll;
|
|
187
|
|
188
|
|
189 i = dmatrix(N, N);
|
|
190 ll = dmatrix(N / 2, N / 2);
|
|
191 lh = dmatrix(N / 2, N / 2);
|
|
192 hl = dmatrix(N / 2, N / 2);
|
|
193 hh = dmatrix(N / 2, N / 2);
|
|
194 v1 = dvector(N * N / 4);
|
|
195 v2 = dvector(N * N / 4);
|
|
196 v3 = dvector(N * N / 4);
|
|
197 v99 = dvector(N * N / 4);
|
|
198
|
|
199 matrix_i2d(image_i, i, N);
|
|
200
|
|
201 //---------------------1o decomposition-------------------
|
|
202 add_hor_add_ver(i, N, ll);
|
|
203 add_hor_sub_ver(i, N, lh);
|
|
204 sub_hor_add_ver(i, N, hl);
|
|
205 sub_hor_sub_ver(i, N, hh);
|
|
206 //---------------------Detect Watermark from all bands----
|
|
207 put_matrix_2_vector(lh, v1, N / 2);
|
|
208 put_matrix_2_vector(hl, v2, N / 2);
|
|
209 put_matrix_2_vector(hh, v3, N / 2);
|
|
210 put_matrix_2_vector(ll, v99, N / 2);
|
|
211 fct2d(v1, N / 2, N / 2);
|
|
212 fct2d(v2, N / 2, N / 2);
|
|
213 fct2d(v3, N / 2, N / 2);
|
|
214 fct2d(v99, N / 2, N / 2);
|
|
215 for (key = 1; key <= 1000; key++) {
|
|
216 m1 = detect_mark(v1, N / 2, key, L1, M1, a_other);
|
|
217 m2 = detect_mark(v2, N / 2, key, L1, M1, a_other);
|
|
218 m3 = detect_mark(v3, N / 2, key, L1, M1, a_other);
|
|
219 m99 = detect_mark(v99, N / 2, key, L2, M2, a_ll);
|
|
220 detect_value = (m1 + m2 + m3 + m99) / 4;
|
|
221 printf("%ld\t%f\t%f\t%f\t%f\t%f\n", key, m1, m2, m3, m99, detect_value);
|
|
222 }
|
|
223 //--------------------------------------------------------
|
|
224 free(v1);
|
|
225 free(v2);
|
|
226 free(v3);
|
|
227 free(v99);
|
|
228 freematrix_d(ll, N / 2);
|
|
229 freematrix_d(hl, N / 2);
|
|
230 freematrix_d(lh, N / 2);
|
|
231 freematrix_d(hh, N / 2);
|
|
232 fclose(in);
|
|
233 }
|
|
234
|
|
235
|
|
236
|
|
237
|