annotate Fotopoulos/cast-sub.c @ 1:647ab0f05aae v0.4

drop, not needed
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 19:58:25 +0200
parents be303a3f5ea8
children cbecc570129d
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 - Subband DCT Transform based */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 /* Module : Casting */
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 : 25/4/2000 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 /* Revision : 7.0 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 /* Developed at : ELLAB */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 /* Electronics Laboratory */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 /* Department of Physics */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 /* University of Patras - GREECE */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 /* Copyleft (c) 1999 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 /* pseudorandom noise generator's code is */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 /* taken from "Numerical Recipes in C" */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 /* FCT implementation from University of Bath */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 #include <stdio.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 #include <stdlib.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 #include <string.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 #include <math.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 #include <float.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 #include <getopt.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 #include "common.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 void add_hor_add_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 void add_hor_sub_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 void sub_hor_add_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 void sub_hor_sub_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 void band_synthesis(double **ll, double **lh, double **hl, double **hh, int N, double **s);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 void watermark(double **i, int N, long key, long int L, long int M, double a);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 double cu[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 double cv[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 int height, width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 void add_hor_add_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 temp[r][c] = (in[r][2 * c] + in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 out[r][c] = (temp[2 * r][c] + temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 void add_hor_sub_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 temp[r][c] = (in[r][2 * c] + in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 out[r][c] = (temp[2 * r][c] - temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 void sub_hor_add_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 temp[r][c] = (in[r][2 * c] - in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 out[r][c] = (temp[2 * r][c] + temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 void sub_hor_sub_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 temp[r][c] = (in[r][2 * c] - in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 out[r][c] = (temp[2 * r][c] - temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 void band_synthesis(double **ll, double **lh, double **hl, double **hh, int N, double **s)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 double b1, b2, b3, b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 for (c = 0; c < N; c++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 b1 = ll[r][c] + lh[r][c] + hl[r][c] + hh[r][c]; //Reconstruct each
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 b2 = ll[r][c] + lh[r][c] - hl[r][c] - hh[r][c]; //of the pixels
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 b3 = ll[r][c] - lh[r][c] + hl[r][c] - hh[r][c];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 b4 = ll[r][c] - lh[r][c] - hl[r][c] + hh[r][c];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 b1 = (b1 > 255.0) ? 255.0 : b1; //Check for positive...
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 b1 = (b1 < 0.0) ? 0.0 : b1; //or negative core!
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 b2 = (b2 > 255.0) ? 255.0 : b2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 b2 = (b2 < 0.0) ? 0.0 : b2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 b3 = (b3 > 255.0) ? 255.0 : b3;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 b3 = (b3 < 0.0) ? 0.0 : b3;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 b4 = (b4 > 255.0) ? 255.0 : b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 b4 = (b4 < 0.0) ? 0.0 : b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 s[2*r][2*c] = b1; //Put them back in
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 s[2*r][2*c + 1] = b2; //the right position
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 s[2*r + 1][2*c] = b3;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 s[2*r + 1][2*c + 1] = b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 void watermark(double **i, int N, long key, long int L, long int M, double a)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 int row, col, count;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 long int elem, temp, seed;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 double *v;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 v = dvector(N * N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 put_matrix_2_vector(i, v, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 fct2d(v, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 seed = key;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 count = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 elem = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 row = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 row--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 col++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 elem++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 if (col < N) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 if (elem > M) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 temp = row * N + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 v[temp] += a * fabs(v[temp]) * gasdev(&seed);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 count++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 } while (row > 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 row = 2 + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 } while (count < L);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 ifct2d(v, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 put_vector_2_matrix(v, i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 free(v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 int main(int argc, char* argv[])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 double **i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 double **o;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 FILE *in;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 FILE *out;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 int N;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 long int M1, L1, M2, L2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 int **image_i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 double **ll, **lh, **hl, **hh;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 double a_ll = 0.1, a_other = 0.2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 int wm_length_1 = 10000, wm_length_ll = 10000, coeff_start_1 = 3000,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 coeff_start_ll = 3000, wm_key = 123;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166 pgm_init(&argc, argv); wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 while ((c = getopt(argc, argv, "a:b:t:m:s:l:k:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 a_ll = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 case 'b':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 a_other = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 case 't':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 coeff_start_1 = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 case 'm':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 wm_length_1 = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 coeff_start_ll = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 wm_length_ll = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 case 'k':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 wm_key = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 open_image(in, &width, &height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 image_i = imatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 load_image(image_i, in, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 if (height == width)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 N = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 fprintf(stderr, "Cannot Proccess non-square images!\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 exit( -11);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 // starting coeff. for 1st level decomp.
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 M1 = coeff_start_1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 // number of coeffs to alter
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 L1 = wm_length_1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 // now the LL band
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 M2 = coeff_start_ll;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 L2 = wm_length_ll;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 i = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 o = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 ll = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 lh = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 hl = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 hh = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 matrix_i2d(image_i, i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 //---------------------1o decomposition-------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 add_hor_add_ver(i, N, ll);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 add_hor_sub_ver(i, N, lh);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 sub_hor_add_ver(i, N, hl);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 sub_hor_sub_ver(i, N, hh);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 //---------------------Watermark medium frequency bands---
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 watermark(lh, N / 2, wm_key, L1, M1, a_other);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 watermark(hl, N / 2, wm_key, L1, M1, a_other);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233 watermark(hh, N / 2, wm_key, L1, M1, a_other);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 watermark(ll, N / 2, wm_key, L2, M2, a_ll);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235 //---------------------Synthesis stage--------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 band_synthesis(ll, lh, hl, hh, N / 2, o);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 matrix_d2i(o, image_i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239 save_image(image_i, out, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247

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