QIM算法和扩频算法分别是什么?
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 20:33:41
QIM算法和扩频算法分别是什么?
QIM算法和扩频算法分别是什么?
QIM算法和扩频算法分别是什么?
经典水印算法QIM
扩频水印并列的算法
例子如下:
#include
#include
#include
double quantize(double value, double delta) {
int q = rint(value / delta);
if ((value - delta * q) RAND_MAX / 2) ? 0 : 1;
bits2[i] = 0;
}
printf("original bits\n");
print_bits(bits, nbits);
l = 140;
dither = malloc(2 * sizeof(double *));
dither[0] = malloc(l * sizeof(double));
dither[1] = malloc(l * sizeof(double));
for (i = 0; i < l; i++) {
dither[0][i] = (random() / (double) RAND_MAX) * delta - delta2;
if (dither[0][i] < 0.0)
dither[1][i] = dither[0][i] + delta2;
else
dither[1][i] = dither[0][i] - delta2;
}
printf("dither 0\n");
print_vector(dither[0], l);
printf("dither 1\n");
print_vector(dither[1], l);
n = l * nbits;
s = malloc(n * sizeof(double));
x = malloc(n * sizeof(double));
y = malloc(n * sizeof(double));
for (i = 0; i < n; i++) {
x[i] = (random() / (double) RAND_MAX) * 255.0;
s[i] = 0.0;
y[i] = 0.0;
}
printf("original\n");
print_vector(x, n);
for (i = 0; i < nbits; i++) {
int bit = bits[i];
quantize_vector(s + l*i, x + l*i, dither[bit], delta, l);
}
printf("watermarked\n");
print_vector(s, n);
for (i = 0; i < n; i++) {
y[i] = s[i] + 5 * ((random() / (double) RAND_MAX) - 0.5);
}
printf("attacked\n");
print_vector(y, n);
for (i = 0; i < n; i++) {
if (i > 200 && i < 300)
y[i] = 0;
}
printf("zeroed\n");
print_vector(y, n);
for (i = 0; i < nbits; i++) {
bits2[i] = decode_vector(y + l*i, dither, delta, l);
}
printf("decoded bits\n");
print_bits(bits2, nbits);
for (i = 0; i < nbits; i++)
if (bits[i] != bits2[i])
printf("error bit #%d\n", i);
exit(0);
}