数字水印matlab程序

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

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

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

资源描述

实用标准文档文案大全clearall;closeall;clc;V=double(imread('D:\lena\lena.jpg'));imshow(mat2gray(V));[iu]=size(V);%计算V的规格r=100;%设置分解矩阵的秩W=rand(i,r)%初始化WH,为非负数H=rand(r,u)maviter=100;%最大迭代次数foriter=1:maviterW=W.*((V./(W*H))*H');%注意这里的三个公式和文中的是对应的W=W./(ones(i,1)*sum(W));H=H.*(W'*(V./(W*H)));endimg_V=W*H;figure;imshow(mat2gray(img_V));首先读入原始图象并设置参数,然后嵌入水印信息,程序代码如下:clear%size=256;block=8;blockno=size/block;LENGTH=size*size/64;Alpha1=0.02;Alpha2=0.1;T1=3;I=zeros(size,size);D=zeros(size,size);BW=zeros(size,size);block_dct1=zeros(block,block);%产生水印序列并对其排序randn('seed',10);watermark1=randn(1,LENGTH);subplot(2,2,1);plot(watermark1);title('watermarc:Gaussiannoise');实用标准文档文案大全subplot(2,2,3);title('edgeoforigineimage')[Y0,I0]=sort(watermark1);%%读入原图象trueImage=imread('H:\DocumentsandSettings\sunhw\MyDocuments\MyPictures\biaozhun.bmp');alfa=.1;LENGTH=2500;subplot(2,2,2);imshow(trueImage);title('origineimage:I');%%对原图象进行DCT变换dctF1=dct2('H:\DocumentsandSettings\sunhw\MyDocuments\MyPictures\biaozhun.bmp');[m,n]=size(dctF1);%%找出水印嵌入位置(幅值较大的n个频域成分)A=dctF1(:);[Y1,I1]=sort(A);x=m*n;k=LENGTH;M=zeros(x,1);%%修改幅值较大的n个频域成分的幅值,嵌入水印(因为两个问题不同,所以有两个注释符)fori=1:xifk=1M(x)=Y1(x)*(1+alfa*Y0(k));k=k-1;elseM(x)=Y1(x);endx=x-1;endN=zeros(x,1);实用标准文档文案大全x=m*n;fori=1:xN(I1(i))=M(i);enda=1;forj=1:nfori=1:mdctF2(i,j)=N(a);a=a+1;endend%%DCT反变换,得到嵌入水印的图象idctF1=idct2(dctF2);subplot(2,2,4);imshow(log(abs(idctF1)),[]);title('embededimage:D');%endI=imread('D:\lena\1.jpg');disp(I);I=double(I)/255;disp(I);I=ceil(I);%%%%%%%%%%显示水印图像%%%%%%%%%%%%%figure(1);subplot(2,3,1);imshow(I),title('水印图像')dimI=size(I);rm=dimI(1);cm=dimI(2);实用标准文档文案大全%%%%%%%%%%%%%%%5以下生成水印信息%%mark=I;alpha=0.05;V=imread('D:\lena\lena.jpg');[iu]=size(V);%计算V的规格r=100;%设置分解矩阵的秩W=rand(i,r)%初始化WH,为非负数H=rand(r,u)maviter=100;%最大迭代次数foriter=1:maviterW=W.*((V./(W*H))*H');%注意这里的三个公式和文中的是对应的W=W./(ones(i,1)*sum(W));H=H.*(W'*(V./(W*H)));endk1=H;psnr_cover=double(V);subplot(2,3,2),imshow(a0,[]),title('载体图像');[r,c]=size(a0);cda0=blkproc(a0,[8,8],'dct2');%%%%%%%%%%%%%%%%%%%%嵌入%%%%%%cda1=cda0;%cda1=256_256fori=1:rm%i=1:32forj=1:cm%j=1:32x=(i-1)*10;y=(j-1)*10;ifmark(i,j)==1k=k1;elsek=k2;endcda1(x+1,y+8)=cda0(x+1,y+8)*(1+alpha*k(1));cda1(x+2,y+7)=cda0(x+2,y+7)*(1+alpha*k(2));cda1(x+3,y+6)=cda0(x+3,y+6)*(1+alpha*k(3));cda1(x+4,y+5)=cda0(x+4,y+5)*(1+alpha*k(4));cda1(x+5,y+4)=cda0(x+5,y+4)*(1+alpha*k(5));cda1(x+6,y+3)=cda0(x+6,y+3)*(1+alpha*k(6));cda1(x+7,y+2)=cda0(x+7,y+2)*(1+alpha*k(7));cda1(x+8,y+1)=cda0(x+8,y+1)*(1+alpha*k(8));endend%%%%%嵌入水印后图像%%%%%%%%%%%%%%a1=blkproc(cda1,[8,8],'idct2');a_1=uint8(a1);实用标准文档文案大全imwrite(a_1,'withmark.bmp','bmp');subplot(2,3,3),imshow(a1,[]),title('嵌入水印后的图像');size=256;block=8;blockno=size/block;%一行有32格LENGTH=size*size/64;Alpha1=0.025;Alpha2=0.1;T1=3;I=zeros(size,size);%产生全矩阵D=zeros(size,size);BW=zeros(size,size);Block_dct1=zeros(block,block);%产生水印,并显示水印信息;subplot(3,2,1);Info='dcf';InfoStrSize=length(Info);%将字符串转换为位数组array=zeros(1,InfoStrSize*8);form=1:InfoStrSizeInfochar=double(Info(m));%%'c'为99forn=1:8array(8*(m-1)+n)=bitget(Infochar,n);%%获得Infochar第n位的值endendplot(array);title('原始水印信息');%显示原图subplot(3,2,2);i=imread('lena.bmp');imshow(i,[]);title('原始图像')%显示prewitt为算子的边缘图BW=edge(i,'prewitt');%BW=edge(I,’Roberts’);%BW=edge(I,’Sobel’);%BW=edge(I,’zerocross’);subplot(3,2,3);imshow(BW);Title('原始图像边缘图');实用标准文档文案大全%嵌入水印l=1;k=1;form=1:blocknoforn=1:blocknox=(m-1)*block+1;y=(n-1)*block+1;%算出每格图像的坐标(x,y),block=8,8*8的图像小格block_dct1=H(x:x+block-1,y:y+block-1);%取原始图像小格中的像素点到block_dct1矩阵中。block_dct1=dct2(block_dct1);%对二维数组进行离散余弦变换。dct是有损压缩如jpeg使用的技术。Dct是可逆的运算BW_8_8=BW(x:x+block-1,y:y+block-1);%得到边界矩阵。ifm=1|n=1T=0;elseT=sum(BW_8_8);T=sum(T);endifTT1Alpha=Alpha2;%block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*mark(k));ifl=(InfoStrSize*8)block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*array(l));l=l+1;endelseAlpha=Alpha1;%block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*mark(k));endBlock_dct=idct2(block_dct1);D(x:x+block-1,y:y+block-1)=Block_dct;k=k+1;endend%显示嵌入水印后的图像subplot(3,2,4);imshow(D,[]);title('嵌入水印图像')%保存该图像D=uint8(D);imwrite(D,'marked.bmp');2:%提取水印D=imread('marked.bmp');D=double(D);I=imread('lena.bmp');I=double(I);array2=zeros(1,InfoStrSize*8);K=1;l=1;form=1:blockno实用标准文档文案大全forn=1:blocknox=(m-1)*block+1;y=(n-1)*block+1;%算出每格图像的坐标(x,y),block=8,8*8的图像小格block_dct1=I(x:x+block-1,y:y+block-1);%取原始图像小格中的像素点到block_dct1矩阵中。block_dct2=D(x:x+block-1,y:y+block-1);Block_dct1=dct2(block_dct1);%对二维数组进行离散余弦变换。dct是有损压缩如jpeg使用的技术。Dct是可逆的运算Block_dct2=dct2(block_dct2);BW_8_8=BW(x:x+block-1,y:y+block-1);%得到边界矩阵。ifm=1|n=1T=0;elseT=sum(BW_8_8);T=sum(T);endifTT1Alpha=Alpha2;%block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*mark(k));ifl=(InfoStrSize*8)tmp=(Block_dct2(1,1)/Block_dct1(1,1)-1);tmp=tmp/Alpha;tmp2=round(tmp);array2(l)=double(tmp2);l=l+1;endelseAlpha=Alpha1;%block_dct1(1,1)=block_dct1(1,1)*(1+Alpha*mark(k));endk=k+1;endendsubplot(3,2,5);plot(array2);title('提取水印');extractedInfo=zeros(InfoStrSize,1);form=1:InfoStrSizeinfochar=0;forn=1:8ifarray2(8*(m-1)+n)==1infochar=infochar+bitset(0,n,1);endendextractedInfo(m)=infochar+extract

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

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

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

×
保存成功