可以运行的水印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; while k<=size(Cr,2)/size(Cwr,2)-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+(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; 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)/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:s