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