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

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