Mercurial > hg > wm
comparison Fotopoulos/test-hart.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 - 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 | |
| 22 int height, width; | |
| 23 | |
| 24 void read_watermark(double **in, int N, int coeff_start, int wm_length, double wm_alpha) | |
| 25 { | |
| 26 int row, col, count; | |
| 27 long int elem, L, M, seed, i; | |
| 28 double a; | |
| 29 double z; | |
| 30 M = coeff_start; | |
| 31 L = wm_length; | |
| 32 a = wm_alpha; | |
| 33 for (i = 1; i <= 1000; i++) { | |
| 34 seed = i; | |
| 35 z = 0.0; | |
| 36 count = 0; | |
| 37 elem = 0; | |
| 38 | |
| 39 for (row = 0; row < N; row++) | |
| 40 for (col = 0; col < N; col++) { | |
| 41 elem++; | |
| 42 if (elem > M && count < L) { | |
| 43 z += in[row][col] * gasdev(&seed); | |
| 44 count++; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 printf("%ld\t%f\n", i, z / L); | |
| 49 } | |
| 50 return ; | |
| 51 } | |
| 52 | |
| 53 int main(int argc, char* argv[]) | |
| 54 { | |
| 55 FILE *in; | |
| 56 int **image; | |
| 57 double **image_i; | |
| 58 double **image_d; | |
| 59 int c; | |
| 60 int N; | |
| 61 int coeff_start = 5000, wm_length = 10000; | |
| 62 double wm_alpha = 0.2; | |
| 63 int width, height; | |
| 64 | |
| 65 pgm_init(&argc, argv); wm_init2(); | |
| 66 | |
| 67 while ((c = getopt(argc, argv, "a:s:l:")) != EOF) { | |
| 68 switch (c) { | |
| 69 case 'a': | |
| 70 wm_alpha = atof(optarg); | |
| 71 break; | |
| 72 case 's': | |
| 73 coeff_start = atoi(optarg); | |
| 74 break; | |
| 75 case 'l': | |
| 76 wm_length = atoi(optarg); | |
| 77 break; | |
| 78 } | |
| 79 } | |
| 80 argc -= optind; | |
| 81 argv += optind; | |
| 82 | |
| 83 in = stdin; | |
| 84 | |
| 85 open_image(in, &width, &height); | |
| 86 image = imatrix(height, width); | |
| 87 load_image(image, in, width, height); | |
| 88 | |
| 89 if (height == width) | |
| 90 N = height; | |
| 91 else { | |
| 92 fprintf(stderr, "Cannot Proccess non-square images!\n"); | |
| 93 exit( -11); | |
| 94 } | |
| 95 | |
| 96 image_i = dmatrix(height, width); | |
| 97 image_d = dmatrix(height, width); | |
| 98 if (image_d == NULL) { | |
| 99 fprintf(stderr, "Unable to allocate the double array\n"); | |
| 100 exit(1); | |
| 101 } | |
| 102 matrix_i2d(image, image_i, N); | |
| 103 hartley(image_i, image_d, N); | |
| 104 read_watermark(image_d, N, coeff_start, wm_length, wm_alpha); | |
| 105 | |
| 106 freematrix_d(image_i, height); | |
| 107 freematrix_d(image_d, height); | |
| 108 fclose(in); | |
| 109 } |
