永发信息网

小弟毕业设计matlab基于扩频的dwt水印嵌入 求大神给个程序代码啊!

答案:1  悬赏:0  手机版
解决时间 2021-11-14 00:53
小弟毕业设计matlab基于扩频的dwt水印嵌入 求大神给个程序代码啊!
最佳答案
%% ---------------------------------------------------------------------%%
% 基于小波变换的扩频图象数字水印-->水印嵌入
%% ---------------------------------------------------------------------%%
start_time=cputime;
k=0.6;
file_name='E:\zy\lena.bmp';
iCover = imread(file_name);
dCover = double(iCover);
dOrigCover = dCover;
Mc=size(iCover,1);
Nc=size(iCover,2);
file_name='E:\zy\copyright.bmp';
iWatermark = imread(file_name);
dWatermark = double(iWatermark);
Mm=size(iWatermark,1);
Nm=size(iWatermark,2);
dWatermarkVector=round(reshape(dWatermark,Mm*Nm,1)./256);
file_name='key.bmp';
key=double(imread(file_name))./256;
rand('state',key);
h = waitbar(0,'Embedding, please wait...');
[cA1,cH1,cV1,cD1] = dwt2(dCover,'haar');
[cA2,cH2,cV2,cD2] = dwt2(cH1,'haar');
[cA3,cH3,cV3,cD3] = dwt2(cV1,'haar');
iLength = length(dWatermarkVector);
for (kk=1:iLength)
pn_sequence_h2=round(2*(rand(Mc/4,Nc/4)-0.5));
pn_sequence_v2=round(2*(rand(Mc/4,Nc/4)-0.5));

pn_sequence_h3=round(2*(rand(Mc/4,Nc/4)-0.5));
pn_sequence_v3=round(2*(rand(Mc/4,Nc/4)-0.5));

if (dWatermarkVector(kk) == 0)
cH2=cH2+k*pn_sequence_h2;
cV2=cV2+k*pn_sequence_v2;
cH3=cH3+k*pn_sequence_h3;
cV3=cV3+k*pn_sequence_v3;
end
waitbar(kk/iLength,h);
end
close(h);
cH1 = idwt2(cA2,cH2,cV2,cD2,'haar',[Mc/2,Nc/2]);
cV1 = idwt2(cA3,cH3,cV3,cD3,'haar',[Mc/2,Nc/2]);
dEmbed = idwt2(cA1,cH1,cV1,cD1,'haar',[Mc,Nc]);
uEmbed = uint8(dEmbed);
imwrite(uEmbed,'dwt.bmp','bmp');
PSNR = psnr(dOrigCover,dEmbed);
elapsed_time=cputime-start_time
figure(1),imshow(iCover,[]);
title('Original Image');
figure(2),imshow(uEmbed,[]);
title(strcat('Watermarked Image',',PSNR=',num2str(PSNR)));
%% END------------------------------------------------------------------%%
%% ---------------------------------------------------------------------%%
% 基于小波变换的扩频图象数字水印-->水印检测
%% ---------------------------------------------------------------------%%
start_time=cputime;
k=0.6;
file_name='~dwt.bmp';
iEmbed = imread(file_name);
dEmbed = double(iEmbed);
Mc=size(iEmbed,1);
Nc=size(iEmbed,2);
file_name='copyright.bmp';
iWatermark = imread(file_name);
dWatermark = double(iWatermark);
ddWatermark=dWatermark;
Mw=size(iWatermark,1);
Nw=size(iWatermark,2);
file_name='key.bmp';
key=double(imread(file_name))./256;
rand('state',key);
MessageVector=ones(1,Mw*Nw);
h = waitbar(0,'Detecting, please wait...');
[cA1,cH1,cV1,cD1] = dwt2(dEmbed,'haar');
[cA2,cH2,cV2,cD2] = dwt2(cH1,'haar');
[cA3,cH3,cV3,cD3] = dwt2(cV1,'haar');
iLength = length(MessageVector);
for (kk=1:iLength)
pn_sequence_h2=round(2*(rand(Mc/4,Nc/4)-0.5));
pn_sequence_v2=round(2*(rand(Mc/4,Nc/4)-0.5));

pn_sequence_h3=round(2*(rand(Mc/4,Nc/4)-0.5));
pn_sequence_v3=round(2*(rand(Mc/4,Nc/4)-0.5));

correlation_h2(kk)=corr2(cH2,pn_sequence_h2);
correlation_v2(kk)=corr2(cV2,pn_sequence_v2);
correlation_h3(kk)=corr2(cH3,pn_sequence_h3);
correlation_v3(kk)=corr2(cV3,pn_sequence_v3);

correlation(kk)=(correlation_h2(kk)+correlation_h3(kk)+correlation_v2(kk)+correlation_v3(kk))/4;
waitbar(kk/iLength,h);
end
for (kk=1:iLength)
if (correlation(kk)> mean(correlation))
MessageVector(kk)=0;
end
end
close(h);
DDetect=reshape(255*MessageVector,Mw,Nw);
Detect = uint8(DDetect);
imwrite(Detect,'watermark jiancai.bmp','bmp');
PSNR = psnr(ddWatermark,DDetect);
elapsed_time=cputime-start_time
CN=corr2(ddWatermark,DDetect);
figure(1),imshow(iWatermark,[]);
title('Original Watermark');
figure(2),imshow(Detect,[])
title(strcat('Detected Watermark',',PSNR=',num2str(PSNR),'CN=',num2str(CN)));
%% END------------------------------------------------------------------%%
% Function:计算PSNR
function PSNR = psnr(ImageA,ImageB)
if (size(ImageA,1) = size(ImageB,1)) or (size(ImageA,2) = size(ImageB,2))
error('ImageA <> ImageB');
dPSNR = 0;
return ;
end
M = size(ImageA,1);
N = size(ImageA,2);

d = 0 ;
for i = 1:M
for j = 1:N
d = d + (ImageA(i,j) - ImageB(i,j)).^2 ;
end
end

dPSNR = -10*log10(d/(255*255*M*N)) ;
return
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
成都温江园林养护公司哪家好
如何测量齿轮模数
计算3(a-2a-3)-5(-5a+a-2)
2005年伍元1234顺子值多少人民币
数据库查询时,报错:org.postgresql.util.PS
5.505写作
吡嘧司特钾片为什么每次只吃半片
芹菜爆肉怎么做
想建lol五人战队,希望高人给起个好听的队员
陕西省汉中市魔芋价格每公斤多少钱
如何复制整个屏幕
一汽大高尔夫2006年初出厂排放标为国几?
去一个不是很发达的城市读大学,会不会没有前
四川省乐山市沐川县新凡乡沐乡2组现在叫什么
公交卡折坏了,里面还有钱,能换吗?
推荐资讯
24岁每天都做重复的工作对吗
精密推台锯推板轴承加过油怎么就推不动
我想问一下 微店v7.7.5版本的封面怎么修改
七律·到韶山的介绍
我已进入腾讯游戏工作室,有什么想问的都来吧
一部日本电影,讲的四男四女在一间屋里,大家因
求娶个女鬼当老婆 txt文件
为什么众多二本院校在211吧里如此高调
小区容积率是怎么算的,多少算是低的
正金酒水超市怎么去啊,有知道地址的么
关于GENESIS安装后出现的问题,请问如何解决
四百除以括号51-46括号乘以八
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?