您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 可以运行的水印MATLAB程序(嵌入-提取-攻击测试等)
input=imread('yuanshituxiang.bmp');subplot(2,2,1);imshow(input);title('原始图像');water=imread('water.bmp');subplot(2,2,2);imshow(water);title('水印');input=double(input);water=double(water);inputr=input(:,:,1);waterr=water(:,:,1);inputg=input(:,:,2);waterg=water(:,:,2);inputb=double(input(:,:,3));waterb=double(water(:,:,3));r=0.06;[Cwr,Swr]=WAVEDEC2(waterr,2,'haar');[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;whilek=size(Cr,2)/size(Cwr,2)-1Cr(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+(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*Cwr(1:size(Cwr,2)/4);g=0.03;[Cwg,Swg]=WAVEDEC2(waterg,2,'haar');[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;whilek=size(Cg,2)/size(Cwg,2)-1Cg(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)/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*size(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;[Cwb,Swb]=WAVEDEC2(waterb,2,'haar');[Cb,Sb]=WAVEDEC2(inputb,2,'haar');%水印的嵌入Cb(1:size(Cwb,2)/16)=Cb(1:size(Cwb,2)/16)+b*Cwb(1:size(Cwb,2)/16);k=0;whilek=size(Cb,2)/size(Cwb,2)-1Cb(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,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: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);fori=1:temp(1);forj=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;watermarked_image_uint8=uint8(pic);imwrite(watermarked_image_uint8,'watermarked','bmp');subplot(2,2,3);imshow(watermarked_image_uint8);title('含水印的图像');yuanshituxiang0=imread('yuanshituxiang.bmp','bmp');[Ca,Sa]=WAVEDEC2(watermarked_image_uint8,2,'haar');[Ca1,Sa1]=WAVEDEC2(yuanshituxiang0,2,'haar');a=0.07;%取加权系数的均值Cwr(1:size(Cwr,2)/4)=(Ca(1:size(Cwr,2)/4)-Ca1(1:size(Cwr,2)/4))/a;bict1=WAVEREC2(Cwr,Swr,'haar');tiqushuiyin=uint8(round(bict1));subplot(2,2,4);imshow(tiqushuiyin,[]);title('提取的水印');%椒盐噪声攻击测试J1=imnoise(watermarked_image_uint8,'salt&pepper',0.01);figure,subplot(1,2,1);imshow(J1);title('加椒盐噪声后的图像');[Ca2,Sa2]=WAVEDEC2(J1,2,'haar');Cwr(1:size(Cwr,2)/4)=(Ca2(1:size(Cwr,2)/4)-Ca1(1:size(Cwr,2)/4))/a;bict1=WAVEREC2(Cwr,Swr,'haar');output2=uint8(round(bict1));subplot(1,2,2);imshow(output2,[]);title('提取加噪声后的水印图像');%JPEG压缩攻击测试imwrite(watermarked_image_uint8,'JPEGyasuo.jpg','jpeg','quality',40);J=imread('JPEGyasuo.jpg');figure,subplot(1,2,1);imshow(J,[]);title('压缩后的水印图像');[Ca3,Sa3]=WAVEDEC2(J,2,'haar');Cwr(1:size(Cwr,2)/4)=(Ca3(1:size(Cwr,2)/4)-Ca1(1:size(Cwr,2)/4))/a;YASUO=WAVEREC2(Cwr,Swr,'haar');output3=uint8(round(YASUO));subplot(1,2,2);imshow(output3,[]);title('提取压缩后的水印图像');
本文标题:可以运行的水印MATLAB程序(嵌入-提取-攻击测试等)
链接地址:https://www.777doc.com/doc-4883827 .html