comparison Fotopoulos-dir/test-sub.c @ 24:9f20bce6184e v0.7

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

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