clear;
%装入原图象I
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:N1
for counter1=1:M1
if(C1(counter1,counter2)>T1)
marked1(counter1,counter2)=rand(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(watermark1*10^16);
axis('square');
title('水印图象')