0
|
1 /* Watermarking program - Fast Cosine Transform based */
|
|
2 /* Module : Testing */
|
|
3 /* Author : Vassilis Fotopoulos */
|
|
4 /* Date : 21/7/1999 */
|
|
5 /* Developed at : ELLAB */
|
|
6 /* Electronics Laboratory */
|
|
7 /* Department of Physics */
|
|
8 /* University of Patras - GREECE */
|
|
9 /* Copyleft (c) 1999 */
|
|
10 /* Testing Program */
|
|
11 /*------------------------------------------------------*/
|
|
12 /* pseudorandom noise generator's code is */
|
|
13 /* taken from "Numerical Recipes in C" */
|
|
14 /* FCT implementation from the 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"
|
13
|
23 #include "pgm.h"
|
0
|
24
|
|
25 double cu[1024];
|
|
26 double cv[1024];
|
|
27 int height, width;
|
|
28
|
|
29 void read_watermark(double *in, int N, int start_coeff, int wm_length, double wm_alpha)
|
|
30 {
|
|
31 int row, col, count;
|
|
32 long int elem, L, M, temp, seed, i;
|
|
33 double z;
|
|
34 M = start_coeff;
|
|
35 L = wm_length;
|
|
36 for (i = 1; i <= 1000; i++) {
|
|
37 seed = i;
|
|
38 z = 0.0;
|
|
39 count = 0;
|
|
40 elem = 0;
|
|
41 row = 2;
|
|
42 col = -1;
|
|
43 do {
|
|
44 do {
|
|
45 row--;
|
|
46 col++;
|
|
47 elem++;
|
|
48 if (col < N) {
|
|
49 if (elem > M) {
|
|
50 temp = row * N + col;
|
|
51 z += in[temp] * gasdev(&seed);
|
|
52 count++;
|
|
53 }
|
|
54 }
|
|
55 } while (row > 0);
|
|
56 row = 2 + col;
|
|
57 col = -1;
|
|
58 } while (count < L);
|
|
59 printf("%ld\t%f\n", i, z / L);
|
|
60 }
|
|
61 return ;
|
|
62 }
|
|
63 //--------------------------------------------------------
|
|
64 void initialize_constants(void)
|
|
65 {
|
|
66 int i;
|
|
67 cu[0] = cv[0] = 0.7071068;
|
|
68 for (i = 1; i < 1024; i++)
|
|
69 cu[i] = cv[i] = 1.0;
|
|
70 }
|
|
71
|
|
72 int main(int argc, char* argv[])
|
|
73 {
|
|
74 FILE *in;
|
|
75 int **image_i;
|
|
76 double *image_f = NULL;
|
|
77 int N;
|
|
78 int c;
|
|
79 int coeff_start = 5000, wm_length = 10000;
|
|
80 double wm_alpha = 0.2;
|
|
81
|
|
82 pgm_init(&argc, argv); wm_init2();
|
|
83
|
|
84 while ((c = getopt(argc, argv, "a:s:l:")) != EOF) {
|
|
85 switch (c) {
|
|
86 case 'a':
|
|
87 wm_alpha = atof(optarg);
|
|
88 break;
|
|
89 case 's':
|
|
90 coeff_start = atoi(optarg);
|
|
91 break;
|
|
92 case 'l':
|
|
93 wm_length = atoi(optarg);
|
|
94 break;
|
|
95 }
|
|
96 }
|
|
97 argc -= optind;
|
|
98 argv += optind;
|
|
99 in = stdin;
|
|
100
|
|
101 open_image(in, &width, &height);
|
|
102 image_i = imatrix(height, width);
|
|
103 load_image(image_i, in, width, height);
|
|
104
|
|
105 if (height == width)
|
|
106 N = height;
|
|
107 else {
|
|
108 fprintf(stderr, "Cannot Proccess non-square images!\n");
|
|
109 exit( -11);
|
|
110 }
|
|
111
|
|
112 initialize_constants();
|
|
113 image_f = (double *)calloc(N * N, sizeof(double));
|
|
114 if (image_f == NULL) {
|
|
115 printf("Unable to allocate the float array\n");
|
|
116 exit(1);
|
|
117 }
|
|
118
|
|
119 put_image_from_int_2_double(image_i, image_f, N);
|
|
120 fct2d(image_f, N, N);
|
|
121 read_watermark(image_f, N, coeff_start, wm_length, wm_alpha);
|
|
122 fclose(in);
|
|
123 freematrix(image_i, height);
|
|
124 free(image_f);
|
13
|
125
|
|
126 exit(EXIT_SUCCESS);
|
0
|
127 }
|