annotate Fotopoulos/test-hart.c @ 22:d8551fb39a5e default tip

Added tag v0.6 for changeset 1c4ccd635a68
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:57:51 +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 a;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 double z;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 M = coeff_start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 L = wm_length;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 a = wm_alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 for (i = 1; i <= 1000; i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 seed = i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 z = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 count = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 elem = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 for (row = 0; row < N; row++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 for (col = 0; col < N; col++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 elem++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 if (elem > M && count < L) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 z += in[row][col] * gasdev(&seed);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 count++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 printf("%ld\t%f\n", i, z / L);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 return ;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 int main(int argc, char* argv[])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 FILE *in;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 int **image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 double **image_i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 double **image_d;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 int N;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 int coeff_start = 5000, wm_length = 10000;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 double wm_alpha = 0.2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 int width, height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 pgm_init(&argc, argv); wm_init2();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 while ((c = getopt(argc, argv, "a:s:l:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 wm_alpha = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 coeff_start = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 wm_length = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 open_image(in, &width, &height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 image = imatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 load_image(image, in, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 if (height == width)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 N = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 fprintf(stderr, "Cannot Proccess non-square images!\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 exit( -11);
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 image_i = dmatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 image_d = dmatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 if (image_d == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 fprintf(stderr, "Unable to allocate the double array\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 matrix_i2d(image, image_i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 hartley(image_i, image_d, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 read_watermark(image_d, N, coeff_start, wm_length, wm_alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 freematrix_d(image_i, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 freematrix_d(image_d, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 fclose(in);
13
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
110
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
111 exit(EXIT_SUCCESS);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 }

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