0
|
1 /* Watermarking program - Hartley Transform based */
|
|
2 /* Module : Casting */
|
|
3 /* Author : Vassilis Fotopoulos */
|
|
4 /* Date : 26/7/1999 */
|
|
5 /* Revision : 2.01a */
|
|
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 /*------------------------------------------------------*/
|
|
15 #include <stdio.h>
|
|
16 #include <stdlib.h>
|
|
17 #include <string.h>
|
|
18 #include <math.h>
|
|
19 #include <float.h>
|
|
20 #include <getopt.h>
|
|
21 #include "common.h"
|
|
22
|
|
23 int height, width;
|
|
24
|
|
25 void add_watermark(double **in, int N, int coeff_start, int wm_length, int wm_key, double wm_alpha)
|
|
26 {
|
|
27 int row, col, count;
|
|
28 long int elem, L, M, temp, seed;
|
|
29 double a;
|
|
30 count = 0;
|
|
31 elem = 0;
|
|
32 M = coeff_start;
|
|
33 L = wm_length;
|
|
34 seed = wm_key;
|
|
35 a = wm_alpha;
|
|
36 for (row = 0; row < N; row++)
|
|
37 for (col = 0; col < N; col++) {
|
|
38 elem++;
|
|
39 if (elem > M && count < L) {
|
|
40 in[row][col] += a * fabs(in[row][col]) * gasdev(&seed);
|
|
41 count++;
|
|
42 }
|
|
43 }
|
|
44
|
|
45 }
|
|
46
|
|
47 //--------------------------------------------------------
|
|
48 int main(int argc, char* argv[])
|
|
49 {
|
|
50 FILE *in, *out;
|
|
51 int **image;
|
|
52 double **image_i;
|
|
53 double **image_d;
|
|
54 int c;
|
|
55 int N;
|
|
56 int coeff_start = 5000, wm_length = 10000, wm_key = 123;
|
|
57 double wm_alpha = 0.2;
|
|
58
|
|
59 pgm_init(&argc, argv); wm_init();
|
|
60
|
|
61 while ((c = getopt(argc, argv, "a:s:l:k:")) != EOF) {
|
|
62 switch (c) {
|
|
63 case 'a':
|
|
64 wm_alpha = atof(optarg);
|
|
65 break;
|
|
66 case 's':
|
|
67 coeff_start = atoi(optarg);
|
|
68 break;
|
|
69 case 'l':
|
|
70 wm_length = atoi(optarg);
|
|
71 break;
|
|
72 case 'k':
|
|
73 wm_key = atoi(optarg);
|
|
74 break;
|
|
75 }
|
|
76 }
|
|
77 argc -= optind;
|
|
78 argv += optind;
|
|
79
|
|
80 in = stdin;
|
|
81 out = stdout;
|
|
82
|
|
83 open_image(in, &width, &height);
|
|
84 image = imatrix(height, width);
|
|
85 load_image(image, in, width, height);
|
|
86
|
|
87 if (height == width)
|
|
88 N = height;
|
|
89 else {
|
|
90 fprintf(stderr, "Cannot Proccess non-square images!\n");
|
|
91 exit( -11);
|
|
92 }
|
|
93
|
|
94 image_i = dmatrix(height, width);
|
|
95 image_d = dmatrix(height, width);
|
|
96 if (image_d == NULL) {
|
|
97 fprintf(stderr, "Unable to allocate the double array\n");
|
|
98 exit(1);
|
|
99 }
|
|
100 matrix_i2d(image, image_i, N);
|
|
101 hartley(image_i, image_d, N);
|
|
102 add_watermark(image_d, N, coeff_start, wm_length, wm_key, wm_alpha);
|
|
103 hartley(image_d, image_i, N);
|
|
104 matrix_d2i(image_i, image, N);
|
|
105 save_image(image, out, width, height);
|
|
106
|
|
107 freematrix_d(image_i, height);
|
|
108 freematrix_d(image_d, height);
|
|
109 fclose(in);
|
|
110 fclose(out);
|
|
111
|
|
112 }
|