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