Mercurial > hg > wm
comparison Fotopoulos-dir/test-hart.c @ 24:9f20bce6184e v0.7
move directories, support netpbm 11
author | Peter Meerwald-Stadler <pmeerw@pmeerw.net> |
---|---|
date | Fri, 20 Dec 2024 13:08:59 +0100 |
parents | Fotopoulos/test-hart.c@71dd4b96221b |
children |
comparison
equal
deleted
inserted
replaced
23:71dd4b96221b | 24:9f20bce6184e |
---|---|
1 /* Watermarking program - Hartley Transform based */ | |
2 /* Module : Testing */ | |
3 /* Author : Vassilis Fotopoulos */ | |
4 /* Date : 26/7/1999 */ | |
5 /* Developed at : ELLAB */ | |
6 /* Electronics Laboratory */ | |
7 /* Department of Physics */ | |
8 /* University of Patras - GREECE */ | |
9 /* Copyleft (c) 1999 */ | |
10 /*------------------------------------------------------*/ | |
11 /* pseudorandom noise generator's code is */ | |
12 /* taken from "Numerical Recipes in C" */ | |
13 /*------------------------------------------------------*/ | |
14 #include <stdio.h> | |
15 #include <stdlib.h> | |
16 #include <string.h> | |
17 #include <math.h> | |
18 #include <float.h> | |
19 #include <getopt.h> | |
20 #include "common.h" | |
21 #include "netpbm/pgm.h" | |
22 | |
23 int height, width; | |
24 | |
25 void read_watermark(double **in, int N, int coeff_start, int wm_length, double wm_alpha) | |
26 { | |
27 int row, col, count; | |
28 long int elem, L, M, seed, i; | |
29 double z; | |
30 M = coeff_start; | |
31 L = wm_length; | |
32 for (i = 1; i <= 1000; i++) { | |
33 seed = i; | |
34 z = 0.0; | |
35 count = 0; | |
36 elem = 0; | |
37 | |
38 for (row = 0; row < N; row++) | |
39 for (col = 0; col < N; col++) { | |
40 elem++; | |
41 if (elem > M && count < L) { | |
42 z += in[row][col] * gasdev(&seed); | |
43 count++; | |
44 } | |
45 } | |
46 | |
47 printf("%ld\t%f\n", i, z / L); | |
48 } | |
49 return ; | |
50 } | |
51 | |
52 int main(int argc, char* argv[]) | |
53 { | |
54 FILE *in; | |
55 int **image; | |
56 double **image_i; | |
57 double **image_d; | |
58 int c; | |
59 int N; | |
60 int coeff_start = 5000, wm_length = 10000; | |
61 double wm_alpha = 0.2; | |
62 int width, height; | |
63 | |
64 pgm_init(&argc, argv); wm_init2(); | |
65 | |
66 while ((c = getopt(argc, argv, "a:s:l:")) != EOF) { | |
67 switch (c) { | |
68 case 'a': | |
69 wm_alpha = atof(optarg); | |
70 break; | |
71 case 's': | |
72 coeff_start = atoi(optarg); | |
73 break; | |
74 case 'l': | |
75 wm_length = atoi(optarg); | |
76 break; | |
77 } | |
78 } | |
79 argc -= optind; | |
80 argv += optind; | |
81 | |
82 in = stdin; | |
83 | |
84 open_image(in, &width, &height); | |
85 image = imatrix(height, width); | |
86 load_image(image, in, width, height); | |
87 | |
88 if (height == width) | |
89 N = height; | |
90 else { | |
91 fprintf(stderr, "Cannot Proccess non-square images!\n"); | |
92 exit( -11); | |
93 } | |
94 | |
95 image_i = dmatrix(height, width); | |
96 image_d = dmatrix(height, width); | |
97 if (image_d == NULL) { | |
98 fprintf(stderr, "Unable to allocate the double array\n"); | |
99 exit(1); | |
100 } | |
101 matrix_i2d(image, image_i, N); | |
102 hartley(image_i, image_d, N); | |
103 read_watermark(image_d, N, coeff_start, wm_length, wm_alpha); | |
104 | |
105 freematrix_d(image_i, height); | |
106 freematrix_d(image_d, height); | |
107 fclose(in); | |
108 | |
109 exit(EXIT_SUCCESS); | |
110 } |