一种基于DWT水印源代码.doc

上传人:美****子 文档编号:77549849 上传时间:2023-03-15 格式:DOC 页数:18 大小:26.50KB
返回 下载 相关 举报
一种基于DWT水印源代码.doc_第1页
第1页 / 共18页
一种基于DWT水印源代码.doc_第2页
第2页 / 共18页
点击查看更多>>
资源描述

《一种基于DWT水印源代码.doc》由会员分享,可在线阅读,更多相关《一种基于DWT水印源代码.doc(18页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、function dwtg1clear all;clc;%保存开始时间start_time=cputime;figure(1);%读出原始图像subplot(1,3,1);input=imread(21310.bmp);imshow(input);title(原始图像);%读出水印subplot(1,3,2);water=imread(华侨大学256bmp.bmp);imshow(water,);title(水印);%三色分离input=double(input);water=double(water);inputr=input(:,:,1);waterr=water(:,:,1);input

2、g=input(:,:,2);waterg=water(:,:,2);inputb=double(input(:,:,3);waterb=double(water(:,:,3);%系数r大.增加鲁棒性,r小增加透明性r=0.06;%水印R的分解Cwr,Swr=WAVEDEC2(waterr,1,haar);%图像R的分解Cr,Sr=WAVEDEC2(inputr,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)-

3、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+

4、(k+1)*size(Cwr,2)/4+. r*Cwr(1+size(Cwr,2)/2:3*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); k=k+1;end;Cr(1:size(Cwr,2)/4)=Cr(1:size(Cwr,2)/4)+r*

5、Cwr(1:size(Cwr,2)/4);g=0.03;%水印G的分解Cwg,Swg=WAVEDEC2(waterg,1,haar);%图像G的分解Cg,Sg=WAVEDEC2(inputg,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)

6、/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)/2:3*size(Cwg,2)/4); Cg(1+3*size(Cg,2)/4+k*siz

7、e(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); 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.12;%水印B的分解Cwb,Swb=WAVEDEC2(waterb,1,haar);%图像B的分解Cb,Sb=WAVEDEC

8、2(inputb,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,

9、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)/2:3*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:

10、3*size(Cb,2)/4+(k+1)*size(Cwb,2)/4+. b*Cwb(1+3*size(Cwb,2)/4:size(Cwb,2); k=k+1;end;Cb(1:size(Cwb,2)/4)=Cb(1:size(Cwb,2)/4)+b*Cwb(1:size(Cwb,2)/4);%图像的重构inputr=WAVEREC2(Cr,Sr,haar);inputg=WAVEREC2(Cg,Sg,haar);inputb=WAVEREC2(Cb,Sb,haar);%三色的叠加temp=size(inputr);pic=zeros(temp(1),temp(2),3);for i=1:te

11、mp(1); for j=1:temp(2); pic(i,j,1)=inputr(i,j); pic(i,j,2)=inputg(i,j); pic(i,j,3)=inputb(i,j); end;end;output=uint8(round(pic);%转化为unit8watermarked_image_uint8=uint8(output);imwrite(watermarked_image_uint8,watermarked1.bmp,bmp);%显示时间elapsed_time=cputime-start_time,%输出结果subplot(1,3,3);imshow(waterma

12、rked_image_uint8);title(水印图像);%以下是水印提取算法clear all;clc;%保存时间start_time=cputime;figure(1);%读出原始图像subplot(1,2,1);input=imread(21310.bmp);imshow(input);title(原始图像);%读出水印图像subplot(1,2,2);watermarked_image=imread(watermarked1.bmp);imshow(watermarked_image,);title(水印图像);%三色分离input=double(input);watermarked

13、_image=double(watermarked_image);inputr=input(:,:,1);watermarked_imager=watermarked_image(:,:,1);inputg=input(:,:,2);watermarked_imageg=watermarked_image(:,:,2);inputb=input(:,:,3);watermarked_imageb=watermarked_image(:,:,3); %水印图像R的分解Cwr,Swr=WAVEDEC2(watermarked_imager,2,haar);%图像R的分解Cr,Sr=WAVEDEC2

14、(inputr,2,haar);%水印图像G的分解Cwg,Swg=WAVEDEC2(watermarked_imageg,2,haar);%图像R的分解Cg,Sg=WAVEDEC2(inputg,2,haar); %水印图像B的分解Cwb,Swb=WAVEDEC2(watermarked_imageb,2,haar);%图像B的分解Cb,Sb=WAVEDEC2(inputb,2,haar); %提取水印小波系数%提取水印R的小波系数r=0.06;for k=0:3 whr(k+1,:)=Cwr(1+size(Cwr,2)/4+k*size(Cwr,2)/16:. size(Cwr,2)/4+(

15、k+1)*size(Cwr,2)/16)-. Cr(1+size(Cr,2)/4+k*size(Cr,2)/16:. size(Cr,2)/4+(k+1)*size(Cr,2)/16); wvr(k+1,:)=Cwr(1+size(Cwr,2)/2+k*size(Cwr,2)/16:. size(Cwr,2)/2+(k+1)*size(Cwr,2)/16)-. Cr(1+size(Cr,2)/2+k*size(Cr,2)/16:. size(Cr,2)/2+(k+1)*size(Cr,2)/16); wdr(k+1,:)=Cwr(1+3*size(Cwr,2)/4+k*size(Cwr,2)/

16、16:. 3*size(Cwr,2)/4+(k+1)*size(Cwr,2)/16)-. Cr(1+3*size(Cr,2)/4+k*size(Cr,2)/16:. 3*size(Cr,2)/4+(k+1)*size(Cr,2)/16);endwhr=(whr(1,:)+whr(2,:)+whr(3,:)+whr(4,:)/(4*r);wvr=(wvr(1,:)+wvr(2,:)+wvr(3,:)+wvr(4,:)/(4*r);wdr=(wdr(1,:)+wdr(2,:)+wdr(3,:)+wdr(4,:)/(4*r);war=(Cwr(1:size(Cwr,2)/16)-Cr(1:size(

17、Cr,2)/16)/r;%提取水印小波系数%提取水印G的小波系数g=0.03;for k=0:3 whg(k+1,:)=Cwg(1+size(Cwg,2)/4+k*size(Cwg,2)/16:. size(Cwg,2)/4+(k+1)*size(Cwg,2)/16)-. Cg(1+size(Cg,2)/4+k*size(Cg,2)/16:. size(Cg,2)/4+(k+1)*size(Cg,2)/16); wvg(k+1,:)=Cwg(1+size(Cwg,2)/2+k*size(Cwg,2)/16:. size(Cwg,2)/2+(k+1)*size(Cwg,2)/16)-. Cg(1

18、+size(Cg,2)/2+k*size(Cg,2)/16:. size(Cg,2)/2+(k+1)*size(Cg,2)/16); wdg(k+1,:)=Cwg(1+3*size(Cwg,2)/4+k*size(Cwg,2)/16:. 3*size(Cwg,2)/4+(k+1)*size(Cwg,2)/16)-. Cg(1+3*size(Cg,2)/4+k*size(Cg,2)/16:. 3*size(Cg,2)/4+(k+1)*size(Cg,2)/16);endwhg=(whg(1,:)+whg(2,:)+whg(3,:)+whg(4,:)/(4*g);wvg=(wvg(1,:)+wvg

19、(2,:)+wvg(3,:)+wvg(4,:)/(4*g);wdg=(wdg(1,:)+wdg(2,:)+wdg(3,:)+wdg(4)/(4*g);wag=(Cwg(1:size(Cwg,2)/16)-Cg(1:size(Cg,2)/16)/g;%提取水印小波系数%提取水印B的小波系数b=0.12;for k=0:3 whb(k+1,:)=Cwb(1+size(Cwb,2)/4+k*size(Cwb,2)/16:. size(Cwb,2)/4+(k+1)*size(Cwb,2)/16)-. Cb(1+size(Cb,2)/4+k*size(Cb,2)/16:. size(Cb,2)/4+(k

20、+1)*size(Cb,2)/16); wvb(k+1,:)=Cwb(1+size(Cwb,2)/2+k*size(Cwb,2)/16:. size(Cwb,2)/2+(k+1)*size(Cwb,2)/16)-. Cb(1+size(Cb,2)/2+k*size(Cb,2)/16:. size(Cb,2)/2+(k+1)*size(Cb,2)/16); wdb(k+1,:)=Cwb(1+3*size(Cwb,2)/4+k*size(Cwb,2)/16:. 3*size(Cwb,2)/4+(k+1)*size(Cwb,2)/16)-. Cb(1+3*size(Cb,2)/4+k*size(Cb

21、,2)/16:. 3*size(Cb,2)/4+(k+1)*size(Cb,2)/16);endwhb=(whb(1,:)+whb(2,:)+whb(3,:)+whb(4,:)/(4*b);wvb=(wvb(1,:)+wvb(2,:)+wvb(3,:)+wvb(4,:)/(4*b);wdb=(wdb(1,:)+wdb(2,:)+wdb(3,:)+wdb(4,:)/(4*b);wab=(Cwb(1:size(Cwb,2)/16)-Cb(1:size(Cb,2)/16)/b;%重构水印图像cwr=war,whr,wvr,wdr;swr(:,1)=sqrt(size(war,2),sqrt(size

22、(war,2),2*sqrt(size(war,2);swr(:,2)=sqrt(size(war,2),sqrt(size(war,2),2*sqrt(size(war,2);wr = waverec2(cwr,swr,haar); cwg=wag,whg,wvg,wdg;swg(:,1)=sqrt(size(wag,2),sqrt(size(wag,2),2*sqrt(size(wag,2);swg(:,2)=sqrt(size(wag,2),sqrt(size(wag,2),2*sqrt(size(wag,2);wg=waverec2(cwg,swg,haar); cwb=wab,whb

23、,wvb,wdb;swb(:,1)=sqrt(size(wab,2),sqrt(size(wab,2),2*sqrt(size(wab,2);swb(:,2)=sqrt(size(wab,2),sqrt(size(wab,2),2*sqrt(size(wab,2);wb=waverec2(cwb,swb,haar);%将R,G,B叠加temp=size(wr); pic=zeros(temp(1),temp(2),3); for i=1:temp(1); for j=1:temp(2); pic(i,j,1)=wr(i,j); pic(i,j,2)=wg(i,j); pic(i,j,3)=wb(i,j); end endoutput=uint8(round(pic);%转化为uint8watermark_image_uint8=uint8(output);imwrite(watermark_image_uint8,华侨大学.bmp,bmp);figure(2);subplot(1,2,1);imshow(华侨大学256bmp.bmp);title(原始水印);subplot(1,2,2);imshow(watermark_image_uint8);title(提取出的水印);这个是彩色图像加彩色水印的,怎么弄成彩色图像嵌入灰度水印啊 第 18 页

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 文案大全

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁