求助,嵌入数字水印实现不了,不知道问题出在哪里?请高手指点!
水印嵌入程序clc;
clear;
p=imread( '载体图.jpg '); %读取载体图像
x= rgb2gray(double (imread('载体图.jpg')));
mc=size(x,1);
nc=size(x,2); %获得宿主的宽和高
[ca1,ch1,cv1,cd1]=dwt2(x,'haar');
[ca2,ch2,cv2,cd2]=dwt2(ca1,'haar');
[ca3,ch3,cv3,cd3]=dwt2(ca2,'haar'); %对宿主进行三层小波分析
A=imread('水印图.bmp');
[m,n]=size(A);
for i=1:20
for x=1:m
for y=1:n
x1=rem(x+y,m)+1;
y1=rem(x+2*y,n)+1;
B(x1,y1)=A(x,y);
end;
end
A=B;
end
subplot(1,2,2); imshow(A); title('置乱水印');
mo=size(A,1);
no=size(A,2); %获得水印的宽和高
[ca5,ch5,cv5,cd5]=dwt2(y,'haar'); %嵌入图像
ch3(17:48,17:48)=ch3(17:48,17:48)+0.1*cd5;
cv3(17:48,17:48)=cv3(17:48,17:48) +0.1*ca5;
ch1(97:128,97:128)=ch1(97:128,97:128)+ 0.1*ch5;
cv2(33:64,33:64)=cv2(33:64,33:64)+ 0.1*ca5;
cv1(97:128,97:128)=cv1(97:128,97:128)+ 0.1*ca5;
ch2(33:64,33:64)=ch2(33:64,33:64)+ 0.1*cv5; %重构图像
w1=idwt2(ca3,ch3,cv3,cd3,'haar');
w2=idwt2(w1,ch2,cv2,cd2,'haar');
w3=idwt2(w2,ch1,cv1,cd1,'haar'); %将嵌入水印的图像写入到文件中
w43_uint8=uint16(w3);
imwrite(w43_uint8,'嵌入有水印的图像.jpg','jpg');
s=imread('嵌入有水印的图像.jpg');
figure(2)
subplot(1,2,1),
imshow(s);title('嵌入有水印的图');
subplot(1,2,2)
imshow(p)
title('载体图');