annotate Fotopoulos/test-pv.c @ 23:71dd4b96221b

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

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