annotate Fotopoulos/cast-pv.c @ 18:3bdb67e76858

mse opt.
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 30 Jan 2009 12:46:49 +0100
parents cbecc570129d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 /* Watermarking program - Fast Cosine Transform based */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 /* Module : Casting */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 /* Author : Vassilis Fotopoulos */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 /* Date : 21/7/1999 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 /* Revision : 2.01a */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 /* Developed at : ELLAB */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 /* Electronics Laboratory */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 /* Department of Physics */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 /* University of Patras - GREECE */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 /* Copyleft (c) 1999 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 /* (without Visual Masking) */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 /* pseudorandom noise generator's code is */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 /* taken from "Numerical Recipes in C" */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 /* FCT implementation from the University of Bath */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 #include <stdio.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 #include <stdlib.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 #include <string.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 #include <math.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 #include <float.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 #include <getopt.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 #include "common.h"
13
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
24 #include "pgm.h"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 double cu[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 double cv[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 int height, width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 void add_watermark(double *in, int N, int coeff_start, int wm_length, int wm_key, double wm_alpha)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int row, col, count;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 long int elem, L, M, temp, seed;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 double a;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 count = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 elem = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 row = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 M = coeff_start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 L = wm_length;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 seed = wm_key;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 a = wm_alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 row--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 col++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 elem++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 if (col < N) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 if (elem > M) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 temp = row * N + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 in[temp] += a * fabs(in[temp]) * gasdev(&seed);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 count++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 } while (row > 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 row = 2 + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 } while (count < L);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 void initialize_constants(void)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 cu[0] = cv[0] = 0.7071068;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 for (i = 1; i < 1024; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 cu[i] = cv[i] = 1.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 int main(int argc, char* argv[])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 FILE *in, *out;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 int **image_i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 double *image_f = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 int N;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 int coeff_start = 5000, wm_length = 10000, wm_key = 123;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 double wm_alpha = 0.2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 pgm_init(&argc, argv); wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 while ((c = getopt(argc, argv, "a:s:l:k:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 wm_alpha = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 coeff_start = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 wm_length = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 case 'k':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 wm_key = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 open_image(in, &width, &height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 image_i = imatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 load_image(image_i, in, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 if (height == width)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 N = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 fprintf(stderr, "Cannot Proccess non-square images!\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 exit( -11);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 initialize_constants();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 image_f = (double *)calloc(N * N, sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 if (image_f == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 printf("Unable to allocate the float array\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 put_image_from_int_2_double(image_i, image_f, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 fct2d(image_f, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 add_watermark(image_f, N, coeff_start, wm_length, wm_key, wm_alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 ifct2d(image_f, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 put_image_from_double_2_int(image_f, image_i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 save_image(image_i, out, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 freematrix(image_i, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 free(image_f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 fclose(out);
13
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
133
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
134 exit(EXIT_SUCCESS);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 }

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