小波实验报告dwt水印

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

一、题目:dwt水印二、目的:编程实现水印的嵌入与还原三、算法及其实现:水印的嵌入与还原小波变换具有空间-频率的多尺度性,对图像的分解可以连续地从低分辨率过渡到高分辨率,也可以对图像整体进行变换,DWT还具有多分辨率特性,可以很好地与人类视觉系统(HVS)特性相匹配。本算法将载体图像进行小波分解,利用公式实现水印信息的嵌入。将2值图像中0和1的值变成-1和1。。将水印入宿主图形重要的小波系数上。水印的提取完全是水印嵌入的逆过程。四、实现工具:Matlab五、程序代码:(1)dwt1_embed.m%嵌入源码clcclearall;%保存开始时间start_time=cputime;k=20;blocksize=8;%设置块的大小%读入原图像file_name='zimu.bmp';cover_object=double(imread(file_name));%原图像的行数与列数Mc=size(cover_object,1);%原图像行数Nc=size(cover_object,2);%原图像列数%最大嵌入信息量max_message=Mc*Nc/(blocksize^2);%读入水印图像file_name='c.bmp';message=double(imread(file_name));%%水印图像的行数与列数Mm=size(message,1);%水印行数Nm=size(message,2);%水印列数message_vector=reshape(message,1,Mm*Nm);%检查水印信息是否过大if(Mm*Nmmax_message)error('水印太大')end%将随机数发生器的状态置为1100randn('state',1100);%产生watermarked_image,并写入原图信息watermarked_image=cover_object;%将图像分块嵌入%当(2,2)(2,3)且message_pad(kk)=0%当(2,2)(2,3)且message_pad(kk)=1%%经过分析可以得出结论:在提取水印时,如果cD1(2,2)cD1(2,3)便是嵌入了水印的黑色像素,%%反之则是嵌入了白色像素x=1;y=1;h=waitbar(0,'嵌入水印,请等待');for(kk=1:length(message_vector))%对块进行DWT变换[cA1,cH1,cV1,cD1]=dwt2(cover_object(x:x+blocksize-1,y:y+blocksize-1),'haar');a=cD1;%如果message_pad(kk)==0if(message_vector(kk)==0)%且(2,2)(2,3),交换它们if(cD1(2,2)cD1(2,3))temp=cD1(2,3);cD1(2,3)=cD1(2,2);cD1(2,2)=temp;end%如果message_pad(kk)==1,elseif(message_vector(kk)==1)%且(2,2)(2,3),交换它们if(cD1(2,2)=cD1(2,3))temp=cD1(2,3);cD1(2,3)=cD1(2,2);cD1(2,2)=temp;endend%检查(2,2),(2,3)的差是否=kifcD1(2,2)cD1(2,3)ifcD1(2,2)-cD1(2,3)kcD1(2,2)=cD1(2,2)+(k/2);cD1(2,3)=cD1(2,3)-(k/2);endelseifcD1(2,3)-cD1(2,2)kcD1(2,3)=cD1(2,3)+(k/2);cD1(2,2)=cD1(2,2)-(k/2);endend%IDWTwatermarked_image(x:x+blocksize-1,y:y+blocksize-1)=idwt2(cA1,cH1,cV1,cD1,'haar',[Mc,Nc]);%移动到下一块if(x+blocksize)=Ncx=1;y=y+blocksize;elsex=x+blocksize;endwaitbar(kk/length(message_vector),h);endclose(h);%转换为uint8并写入dwt_watermarked.bmpwatermarked_image_uint=uint8(watermarked_image);imwrite(watermarked_image_uint,'dwt_watermarked.bmp','bmp');%显示运行时间elapsed_time=cputime-start_time,%计算psnr值psnr=psnr(cover_object,watermarked_image),%显示图像figure(1)imshow(message);title('水印');figure(2)subplot(1,2,1);imshow(watermarked_image,[])title('嵌入水印图像')subplot(1,2,2);imshow('zimu.bmp');title('原图');(2)dwt1_recover.m%DWT源码%提取源码clearall;%保存开始时间start_time=cputime;blocksize=8;%设置块的大小%读入嵌入水印图像file_name='dwt_watermarked.bmp';watermarked_image=double(imread(file_name));%嵌入水印图像的行数与列数Mw=size(watermarked_image,1);%嵌入水印图像的行数Nw=size(watermarked_image,2);%嵌入水印图像的列数%最大嵌入信息量max_message=Mw*Nw/(blocksize^2);%读入原始水印file_name='c.bmp';orig_watermark=double(imread(file_name));%原始水印的行数与列数Mo=size(orig_watermark,1);%原始水印的行数No=size(orig_watermark,2);%原始水印的列数%将图像分块提取水印x=1;y=1;h=waitbar(0,'水印提取中,请等待');for(kk=1:max_message)%对块进行dwt变换[cA1,cH1,cV1,cD1]=dwt2(watermarked_image(x:x+blocksize-1,y:y+blocksize-1),'haar');%如果cD1(2,2)cD1(3,3)那么message_vector(kk)=0%否则message_vector(kk)=1ifcD1(2,2)cD1(3,3)message_vector(kk)=0;elsemessage_vector(kk)=1;end%移动到下一块if(x+blocksize)=Mwx=1;y=y+blocksize;elsex=x+blocksize;endwaitbar(kk/max_message,h);endclose(h);%将message重新排列message_vector=message_vector(1,1:Mo*No);%%只需前Mo*No个message=reshape(message_vector,Mo,No);%显示运行时间elapsed_time=cputime-start_time,%显示提取水印与原始水印figure(3)subplot(1,2,1);imshow(message,[]);title('提取水印')subplot(1,2,2);imshow(orig_watermark,[])title('原始水印');六、运行结果:1、把C嵌入到图形中把c从水印图形中提取出来并对比七:结果分析:

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功