DCT数字水印matlab
时间: 2023-11-06 22:57:02 浏览: 126
matlab dct 数字水印
基于DCT数字水印算法的matlab实现如下所示:
```matlab
M = 256; % 原图像长度
N = 32; % 水印图像长度
K = 8;
I = zeros(M, M);
II = zeros(K, K);
B = zeros(M, M);
Idct = zeros(K, K);
D = zeros(M, M);
% 读取原图像
I = imread('C:\Users\Administrator\Desktop\liu.jpg');
subplot(2,2,1);
imshow(I);
title('原图像');
% 读取水印图像
G = imread('C:\Users\Administrator\Desktop\niu.bmp');
subplot(2,2,2);
imshow(G);
title('水印序列');
% 嵌入水印
T = 1;
for m = 1:N
for n = 1:N
x = (m-1)*K + 1;
y = (n-1)*K + 1;
II = I(x:x+K-1, y:y+K-1);
Idct = dct2(II);
if x == 1 && y == 1
alfa = 0.002;
else
alfa = 0;
end
B = Idct * (1 + alfa * mark(T));
Bidct = idct2(B);
I(x:x+K-1, y:y+K-1) = Bidct;
T = T + 1;
end
end
% 显示嵌入水印后的图像
subplot(2,2,3);
imshow(I);
title('嵌入后的图像');
imwrite(I, '嵌入后的图像.bmp');
% 相关性比较
figure;
for i = 1:50
mark2 = randn(1024, 1);
% 计算相关值
c = (mark2' * mark) / sqrt(mark2' * mark2);
stem(i, c);
hold on;
end
```
阅读全文