comparison Fotopoulos-dir/cast-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/cast-hart.c@cbecc570129d
children
comparison
equal deleted inserted replaced
23:71dd4b96221b 24:9f20bce6184e
1 /* Watermarking program - Hartley Transform based */
2 /* Module : Casting */
3 /* Author : Vassilis Fotopoulos */
4 /* Date : 26/7/1999 */
5 /* Revision : 2.01a */
6 /* Developed at : ELLAB */
7 /* Electronics Laboratory */
8 /* Department of Physics */
9 /* University of Patras - GREECE */
10 /* Copyleft (c) 1999 */
11 /*------------------------------------------------------*/
12 /* pseudorandom noise generator's code is */
13 /* taken from "Numerical Recipes in C" */
14 /*------------------------------------------------------*/
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <math.h>
19 #include <float.h>
20 #include <getopt.h>
21 #include "common.h"
22 #include "netpbm/pgm.h"
23
24 int height, width;
25
26 void add_watermark(double **in, int N, int coeff_start, int wm_length, int wm_key, double wm_alpha)
27 {
28 int row, col, count;
29 long int elem, L, M, seed;
30 double a;
31 count = 0;
32 elem = 0;
33 M = coeff_start;
34 L = wm_length;
35 seed = wm_key;
36 a = wm_alpha;
37 for (row = 0; row < N; row++)
38 for (col = 0; col < N; col++) {
39 elem++;
40 if (elem > M && count < L) {
41 in[row][col] += a * fabs(in[row][col]) * gasdev(&seed);
42 count++;
43 }
44 }
45
46 }
47
48 //--------------------------------------------------------
49 int main(int argc, char* argv[])
50 {
51 FILE *in, *out;
52 int **image;
53 double **image_i;
54 double **image_d;
55 int c;
56 int N;
57 int coeff_start = 5000, wm_length = 10000, wm_key = 123;
58 double wm_alpha = 0.2;
59
60 pgm_init(&argc, argv); wm_init();
61
62 while ((c = getopt(argc, argv, "a:s:l:k:")) != EOF) {
63 switch (c) {
64 case 'a':
65 wm_alpha = atof(optarg);
66 break;
67 case 's':
68 coeff_start = atoi(optarg);
69 break;
70 case 'l':
71 wm_length = atoi(optarg);
72 break;
73 case 'k':
74 wm_key = atoi(optarg);
75 break;
76 }
77 }
78 argc -= optind;
79 argv += optind;
80
81 in = stdin;
82 out = stdout;
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 add_watermark(image_d, N, coeff_start, wm_length, wm_key, wm_alpha);
104 hartley(image_d, image_i, N);
105 matrix_d2i(image_i, image, N);
106 save_image(image, out, width, height);
107
108 freematrix_d(image_i, height);
109 freematrix_d(image_d, height);
110 fclose(in);
111 fclose(out);
112 exit(EXIT_SUCCESS);
113 }

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