以下是水印提取代码:
clear all;
% save start time
start_time=cputime;
% read in the watermarked object
file_name='dwt_watermarked.bmp';
watermarked_image=double(imread(file_name));
% determine size of watermarked image
Mw=size(watermarked_image,1); %Height
Nw=size(watermarked_image,2); %Width
% read in original watermark
file_name='1(1).bmp';
orig_watermark=double(imread(file_name));
% determine size of original watermark
Mo=size(orig_watermark,1); %Height
No=size(orig_watermark,2); %Width
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
rand('state',16);
% initalize message to all ones
message_vector=ones(1,Mo*No);
[cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');
% add pn sequences to H1 and V1 componants when message = 0
pn_sequence_h=round(2*(rand(Mw/2,Nw/2)-0.5));
pn_sequence_v=round(2*(rand(Mw/2,Nw/2)-0.5));
for (kk=1:length(message_vector))
correlation_h(kk)=corr2(cH1,pn_sequence_h);
correlation_v(kk)=corr2(cV1,pn_sequence_v);
correlation(kk)=(correlation_h(kk)+correlation_v(kk))/2;
end
for (kk=1:length(message_vector))
if (correlation(kk) > mean(correlation))
message_vector(kk)=0;
end
end
% reshape the message vector and display recovered watermark.
figure(2)
message=reshape(message_vector,Mo,No);
imshow(message,[])
title('Recovered Watermark')
% display processing time
elapsed_time=cputime-start_time;
运行结果出来什么都没有,不知道哪里不合适,嵌入过程没有问题。水印图像选取的是512*512的8位lena灰度图像,水印图像选取的是254*244的8位二值图像。_key图像选取的是196*210的8位灰度图像。

_key.jpg

水印

嵌入水印后的图片
鉴于上传的需要,已将图片转为Jpg格式,要运行程序的话先另存为bmp格式吧。希望能得到大家的帮助,小弟不胜感激了。。。
clear all;
% save start time
start_time=cputime;
% read in the watermarked object
file_name='dwt_watermarked.bmp';
watermarked_image=double(imread(file_name));
% determine size of watermarked image
Mw=size(watermarked_image,1); %Height
Nw=size(watermarked_image,2); %Width
% read in original watermark
file_name='1(1).bmp';
orig_watermark=double(imread(file_name));
% determine size of original watermark
Mo=size(orig_watermark,1); %Height
No=size(orig_watermark,2); %Width
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% reset MATLAB's PN generator to state "key"
rand('state',16);
% initalize message to all ones
message_vector=ones(1,Mo*No);
[cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');
% add pn sequences to H1 and V1 componants when message = 0
pn_sequence_h=round(2*(rand(Mw/2,Nw/2)-0.5));
pn_sequence_v=round(2*(rand(Mw/2,Nw/2)-0.5));
for (kk=1:length(message_vector))
correlation_h(kk)=corr2(cH1,pn_sequence_h);
correlation_v(kk)=corr2(cV1,pn_sequence_v);
correlation(kk)=(correlation_h(kk)+correlation_v(kk))/2;
end
for (kk=1:length(message_vector))
if (correlation(kk) > mean(correlation))
message_vector(kk)=0;
end
end
% reshape the message vector and display recovered watermark.
figure(2)
message=reshape(message_vector,Mo,No);
imshow(message,[])
title('Recovered Watermark')
% display processing time
elapsed_time=cputime-start_time;
运行结果出来什么都没有,不知道哪里不合适,嵌入过程没有问题。水印图像选取的是512*512的8位lena灰度图像,水印图像选取的是254*244的8位二值图像。_key图像选取的是196*210的8位灰度图像。

_key.jpg

水印

嵌入水印后的图片
鉴于上传的需要,已将图片转为Jpg格式,要运行程序的话先另存为bmp格式吧。希望能得到大家的帮助,小弟不胜感激了。。。
