文档介绍:基于DCT变换域的水印嵌入和提取一、原始图像被随机攻击的源程序:%functionrandom_damage()functionrandom_damage()file_name='';oriwat_img=imread(file_name);%computethesizeH=size(oriwat_img,1);W=size(oriwat_img,2);%随机产生行、列,破坏row1=unidrnd(512);row2=unidrnd(512);column1=unidrnd(512);column2=unidrnd(512);if(row1>row2)temp=row1;row1=row2;row2=temp;endif(column1>column2)temp=column1;column1=column2;column2=temp;endattack_img=oriwat_img;fori=row1:row2forj=column1:column2attack_img(i,j)=unidrnd(255);endend%settheattackedimageimwrite(attack_img,'','bmp');count=(column2-column1+1)*(row2-row1+1)subplot(1,2,1);imshow(oriwat_img)title('OriginalWatermarkedImage')subplot(1,2,2);imshow(attack_img)title('AttackedImage')该实验程序所产生的实验结果为:由于该程序是通过产生随机序列而对图像进行攻击的,所以所产生的的实验结果每次都会有所不同,而上图的实验结果也是所显示的几个图像里面被攻击的效果最明显程度最严重的一个。普通水印的嵌入和提取的源程序:M=8;%原图像长度N=8;%水印图像长度K=8;I=zeros(M,M);J=zeros(N,N);B=zeros(K,K);I=imread('');%读入原图像subplot(221)imshow(I);title('原图像');%显示水印图像%randn('seed',10);%mark=randn(1024,1);%subplot(2,2,2);%plot(mark);%title('水印序列');L=imread('');J=rgb2gray(L)subplot(2,2,2);imshow(J);title('水印图像');%嵌入水印T=1;form=1:Nforn=1:Nx=(m-1)*K+1;y=(n-1)*K+1;B=I(x:x+K-1,y:y+K-1);%将原图分成8*8的子块B=dct2(B);%对子块进行DCT变换ifx==1&y==1a=;elsea=;endB=B*(1+a*mark(T));%嵌入水印B=idct2(B);%进行DCT反变换I(x:x+K-1,y:y+K-1)=B;T=T+1;endendsubplot(2,2,3);imshow(I);%显示嵌入水印后的图像title('嵌入水印后的图像');imwrite(I,'');%从嵌入水印的图像中提取水印I=i