有没有基于小波变化的图像数字水印技术的程序代码(matlab)(图像置乱,水印嵌入,提取,水印攻击)
发布网友
发布时间:2022-06-13 21:01
我来回答
共2个回答
热心网友
时间:2023-10-15 15:25
clear;
%装入原图像1
load woman;
I=X;
%小波函数
type = 'db1';
% 2维离散Daubechies小波变换
[CA1, CH1, CV1, CD1] = dwt2(I,type);
C1 = [CH1 CV1 CD1];
%系数矩阵大小
[length1, width1] = size(CA1);
[M1, N1] = size(C1);
% 定义阈值T1
T1 =50;
alpha = 0.2;
%在图像中加入水印
for counter2 = 1: 1: N1
for counter1 = 1: 1: M1
if( C1(counter1, counter2) > T1 )
marked1(counter1,counter2) = randn(1,1);
NEWC1(counter1, counter2) = double( C1(counter1, counter2) ) ...
+alpha * abs( double( C1(counter1, counter2) ) ) * marked1(counter1,counter2) ;
else
marked1(counter1, counter2) = 0;
NEWC1(counter1, counter2) = double( C1(counter1, counter2) );
end;
end;
end;
%重构图像
NEWCH1 = NEWC1(1:length1, 1:width1);
NEWCV1 = NEWC1(1:length1, width1+1:2*width1);
NEWCD1 = NEWC1(1:length1, 2*width1+1:3*width1);
R1 = double( idwt2(CA1, NEWCH1, NEWCV1, NEWCD1, type) );
%分离水印
watermark1 = double(R1) - double(I);
figure(1);
subplot(1,2,1);
image(I);
axis('square');
title('原始图像');
subplot(1,2,2);
imshow(R1/250);
axis('square');
title('Daubechies小波变换后图像');
figure(2);
imshow(watermark1*10^16);
axis('square');
title('水印图像');
% 水印检测
newmarked1 = reshape(marked1, M1*N1, 1);
% 检测阈值
T2 = 60;
for counter2 = 1: 1: N1
for counter1 = 1: 1: M1
if( NEWC1(counter1, counter2) >T2 )
NEWC1X(counter1, counter2) = NEWC1(counter1, counter2);
else
NEWC1X(counter1, counter2) = 0;
end;
end;
end;
NEWC1X = reshape(NEWC1X, M1*N1, 1);
correlation1 = zeros(1000,1);
for corrcounter = 1: 1: 1000
if( corrcounter == 500)
correlation1(corrcounter,1) = NEWC1X'*newmarked1 / (M1*N1);
else
rnmark = randn(M1*N1,1);
correlation1(corrcounter,1) = NEWC1X'*rnmark / (M1*N1);
end;
end;
% 计算阈值
originalthreshold = 0;
for counter2 = 1: 1: N1
for counter1 = 1: 1: M1
if( NEWC1(counter1, counter2) > T2 )
originalthreshold = originalthreshold + ...
abs( NEWC1(counter1, counter2) );
end;
end;
end;
originalthreshold = originalthreshold * alpha / (2*M1*N1);
corrcounter = 1000;
originalthresholdvector = ones(corrcounter,1) * originalthreshold;
figure(3);
plot(correlation1, '-');
hold on;
plot(originalthresholdvector, '--');
title('原始的加水印图像');
xlabel('水印');
ylabel('检测响应');
另外,还有一个程序,希望可以帮到您!
clear all;
start_time=cputime;
I1=imread('hill1.jpg');
subplot(1,2,1);imshow(I1);
xlabel('(a)原始图像');
I2=imread('hill2.jpg');
subplot(1,2,2);imshow(I2,[]);
xlabel('(b)水印');
%三色分离
I1=double(I1);
I2=double(I2);
I1r=I1(:,:,1);
I2r=I2(:,:,1);
I1g=I1(:,:,2);
I2g=I2(:,:,2);
I1b=double(I1(:,:,3));
I2b=double(I2(:,:,3));
%系数r大,增加鲁棒性,r小增加透明性
r=0.05;
%水印R的分解
[Cwr,Swr]=wavedec2(I2r,1,'haar');
%图像R的分解
[Cr,Sr]=wavedec2(I1r,2,'haar');
%水印的嵌入
Cr(1:size(Cwr,2)/16)=Cr(1:size(Cwr,2)/16)+r*Cwr(1:size(Cwr,2)/16);
k=0;
while k<=size(Cr,2)/size(Cwr,2)-1
Cr(1+size(Cr,2)/4+k*size(Cwr,2)/4:size(Cr,2)/4+(k+1)*size(Cwr,2)/4)...
=Cr(1+size(Cr,2)/4+k*size(Cwr,2)/4:size(Cr,2)/4+(k+1)*size(Cwr,2)/4)+...
r*Cwr(1+size(Cwr,2)/4:size(Cwr,2)/2);
Cr(1+size(Cr,2)/2+k*size(Cwr,2)/4:size(Cr,2)/2+(k+1)*size(Cwr,2)/4)...
=Cr(1+size(Cr,2)/2+k*size(Cwr,2)/4:size(Cr,2)/2+(k+1)*size(Cwr,2)/4)+...
r*Cwr(1+size(Cwr,2)/4:size(Cwr,2)/4);
Cr(1+3*size(Cr,2)/4+k*size(Cwr,2)/4:3*size(Cr,2)/4+(k+1)*size(Cwr,2)/4)...
=Cr(1+3*size(Cr,2)/4+k*size(Cwr,2)/4:3*size(Cr,2)/4+(k+1)*size(Cwr,2)/4)+...
r*Cwr(1+3*size(Cwr,2)/4:size(Cwr,2)/2);
k=k+1;
end
Cr(1:size(Cwr,2)/4)=Cr(1:size(Cwr,2)/4)+r*Cwr(1:size(Cwr,2)/4);
g=0.025;
%水印G的分解
[Cwg,Swg]=wavedec2(I2g,1,'haar');
%图像G的分解
[Cg,Sg]=wavedec2(I1g,2,'haar');
%水印的嵌入
Cg(1:size(Cwg,2)/16)=Cg(1:size(Cwg,2)/16)+g*Cwg(1:size(Cwg,2)/16);
k=0;
while k<=size(Cg,2)/size(Cwg,2)-1
Cg(1+size(Cg,2)/4+k*size(Cwg,2)/4:size(Cg,2)/4+(k+1)*size(Cwg,2)/4)...
=Cg(1+size(Cg,2)/4+k*size(Cwg,2)/4:size(Cg,2)/4+(k+1)*size(Cwg,2)/4)+...
g*Cwg(1+size(Cwg,2)/4:size(Cwg,2)/2);
Cg(1+size(Cg,2)/2+k*size(Cwg,2)/4:size(Cg,2)/2+(k+1)*size(Cwg,2)/4)...
=Cg(1+size(Cg,2)/2+k*size(Cwg,2)/4:size(Cg,2)/2+(k+1)*size(Cwg,2)/4)+...
g*Cwg(1+size(Cwg,2)/4:size(Cwg,2)/4);
Cg(1+3*size(Cg,2)/4+k*size(Cwg,2)/4:3*size(Cg,2)/4+(k+1)*size(Cwg,2)/4)...
=Cg(1+3*size(Cg,2)/4+k*size(Cwg,2)/4:3*size(Cg,2)/4+(k+1)...
*size(Cwg,2)/4)+g*Cwg(1+3*size(Cwg,2)/4:size(Cwg,2)/2);
k=k+1;
end
Cg(1:size(Cwg,2)/4)=Cg(1:size(Cwg,2)/4)+g*Cwg(1:size(Cwg,2)/4);
b=0.1;
%水印B的分解
[Cwb,Swb]=wavedec2(I2b,1,'haar');
%图像B的分解
[Cb,Sb]=wavedec2(I1b,2,'haar');
%水印的嵌入
Cb(1:size(Cwb,2)/16)=Cb(1:size(Cwb,2)/16)+b*Cwb(1:size(Cwb,2)/16);
k=0;
while k<=size(Cb,2)/size(Cwb,2)-1
Cb(1+size(Cb,2)/4+k*size(Cwb,2)/4:size(Cb,2)/4+(k+1)*size(Cwb,2)/4)...
=Cb(1+size(Cb,2)/4+k*size(Cwb,2)/4:size(Cb,2)/4+(k+1)*size(Cwb,2)/4)+...
b*Cwb(1+size(Cwb,2)/4:size(Cwb,2)/2);
Cb(1+size(Cb,2)/2+k*size(Cwb,2)/4:size(Cb,2)/2+(k+1)*size(Cwb,2)/4)...
=Cb(1+size(Cb,2)/2+k*size(Cwb,2)/4:size(Cb,2)/2+(k+1)*size(Cwb,2)/4)+...
b*Cwb(1+size(Cwb,2)/4:size(Cwb,2)/4);
Cb(1+3*size(Cb,2)/4+k*size(Cwb,2)/4:3*size(Cb,2)/4+(k+1)*size(Cwb,2)/4)...
=Cb(1+3*size(Cb,2)/4+k*size(Cwb,2)/4:3*size(Cb,2)/4+(k+1)...
*size(Cwb,2)/4)+b*Cwb(1+3*size(Cwb,2)/4:size(Cwb,2)/2);
k=k+1;
end
Cb(1:size(Cwb,2)/4)=Cb(1:size(Cwb,2)/4)+b*Cwb(1:size(Cwb,2)/4);
%图像重构
I1r=waverec2(Cr,Sr,'haar');
I1g=waverec2(Cg,Sg,'haar');
I1b=waverec2(Cb,Sb,'haar');
%三色的叠加
temp=size(I1r);
pic=zeros(temp(1),temp(2),3);
for i=1:temp(1);
for j=1:temp(2);
pic(i,j,1)=I1r(i,j);
pic(i,j,2)=I1g(i,j);
pic(i,j,3)=I1b(i,j);
end
end
ot=uint8(round(pic));
%转化为uint8
I2_image_u=uint8(ot);
imwrite(I2_image_u,'watemarked.bmp','bmp');
%显示时间
e_time=cputime-start_time
figure;imshow(I2_image_u);
xlabel('数字图像水印效果')
热心网友
时间:2023-10-15 15:26
我也是做这个毕设~~求分享!