⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dct_emb.m

📁 一个基于dct变换的数字水印算法的源程序,可供进行数字水印学习和研究的学生及科研工作者学习参考
💻 M
字号:
function  [Q watermarked]=dct_em(ZT,tao)
%tao=-0.01%阈值
Q_table=[16 11 10 16 24 40 51 61;
            12 12 14 19 26 58 60 55;
        14 13 16 24 40 57 69 56;
        14 17 22 29 51 87 80 62;
        18 22 37 56 68 109 103 77;
        24 35 55 64 81 104 113 92;
        49 64 78 87 103 121 120 101;
        72 92 95 98 112 100 103 99
        ];

%ZT=imread('lena256.bmp');
%ZT=ZT(17:32,1:8);
[m n]=size(ZT);
watermarked=zeros(m,n);
quality=50;
%块dct变换
% for i=1:(m/8);
%     for j=1:(n/8);
%         width=(i-1)*8+1;
%         height=(j-1)*8+1;
%         imdct(width:(width+7),height:(height+7))=dct2(ZT(width:(width+7),height:(height+7)));
%     end
% end
%开辟要比较的数据空间
Q=zeros(1,m*n/8/8/2*6);
%比较zig-zag前6个对应系数
% k=1;
% for i=1:(m/8/2);
%     for j=1:(n/8);
%         width=(i-1)*16+1;
%         height=(j-1)*8+1;
%         l=(k-1)*6+1;
%         if imdct(width,height)-imdct(width+8,height)<0
%             Q(l)=0;
%         else
%             Q(l)=1;
%         end
%         if imdct(width+1,height)-imdct(width+9,height)<0
%             Q(l+1)=0;
%         else
%             Q(l+1)=1;
%         end
%         if imdct(width,height+1)-imdct(width+8,height+1)<0
%             Q(l+2)=0;
%         else
%             Q(l+2)=1;
%         end
%         if imdct(width,height+2)-imdct(width+8,height+2)<0
%             Q(l+3)=0;
%         else
%             Q(l+3)=1;
%         end
%         if imdct(width+1,height+1)-imdct(width+9,height+1)<0
%             Q(l+4)=0;
%         else
%             Q(l+4)=1;
%         end
%         if imdct(width+2,height)-imdct(width+10,height)<0
%             Q(l+5)=0;
%         else
%             Q(l+5)=1;   
%         end
%          k=k+1;
%     end
% end
% imwrite(uint8(J2),'lena256.jpg','quality',quality);
% yy=imread('lena256.jpg');

wm_cof=[1 1;2 1;1 2;1 3;2 2;3 1];
em_cof=[1 4;2 3;3 2;4 1;4 2;3 3];
%em_cof=[4 4;4 5;5 4;2 6;6 2;3 5];

NN=size(em_cof,1);

err=1;

watermarked=ZT;
%tao=-0.01;

while err>0
    err=0;
 
    for i=1:(m/8);
    for j=1:(n/8);
        width=(i-1)*8+1;
        height=(j-1)*8+1;
        imdct(width:(width+7),height:(height+7))=dct2(watermarked(width:(width+7),height:(height+7)));
    end
    end
    
k=1;
for i=1:(m/8/2);
    for j=1:(n/8);
        width=(i-1)*16;
        height=(j-1)*8;
        l=(k-1)*6+1;
        for ppp=1:6
%if round((imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2))-imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2)))/(Q_table(wm_cof(ppp,1),wm_cof(ppp,2))+1))<tao
%   if round((imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2))-imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2)))/(Q_table(wm_cof(ppp,1),wm_cof(ppp,2))))<tao

    %  if round((imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2))-imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2))))<tao
  
            if round(imdct(width+wm_cof(ppp,1),height+wm_cof(ppp,2)))-round(imdct(width+wm_cof(ppp,1)+8,height+wm_cof(ppp,2)))<tao
         
  Q(l+ppp)=0;
        else
            Q(l+ppp)=1;
        end
        end
%         if round(imdct(width+1,height)/Q_table(em_cof(2,1),em_cof(2,2)))-round(imdct(width+9,height)/Q_table(em_cof(2,1),em_cof(2,2)))<tao
%             Q(l+1)=0;
%         else
%             Q(l+1)=1;
%         end
%         if round(imdct(width,height+1)/Q_table(em_cof(3,1),em_cof(3,2)))-round(imdct(width+8,height+1)/Q_table(em_cof(3,1),em_cof(3,2)))<tao
%             Q(l+2)=0;
%         else
%             Q(l+2)=1;
%         end
%         if round(imdct(width,height+2)/Q_table(em_cof(4,1),em_cof(4,2)))-round(imdct(width+8,height+2)/Q_table(em_cof(4,1),em_cof(4,2)))<tao
%             Q(l+3)=0;
%         else
%             Q(l+3)=1;
%         end
%         if round(imdct(width+1,height+1)/Q_table(em_cof(5,1),em_cof(5,2)))-round(imdct(width+9,height+1)/Q_table(em_cof(5,1),em_cof(5,2)))<tao
%             Q(l+4)=0;
%         else
%             Q(l+4)=1;
%         end
%         if round(imdct(width+2,height)/Q_table(em_cof(6,1),em_cof(6,2)))-round(imdct(width+10,height)/Q_table(em_cof(6,1),em_cof(6,2)))<tao
%             Q(l+5)=0;
%         else
%             Q(l+5)=1;   
%         end
         k=k+1;
    end
end
    
aQ=Q;

k=1;
 for i=1:(m/8/2)
    for j=1:(n/8)

        width=(i-1)*16;
        height=(j-1)*8;
        l=(k-1)*6+1;
     
         for kk=1:3  
         qstep=Q_table(em_cof(kk,1),em_cof(kk,2))+1;
         orcof=imdct(width+em_cof(kk,1),height+em_cof(kk,2));
          imdct(width+em_cof(kk,1),height+em_cof(kk,2))=round(orcof/qstep)*qstep;
          
         if mod(round(imdct(width+em_cof(kk,1),height+em_cof(kk,2))/qstep),2)~=Q(l)
             err=err+1;
            %%%%%%%%%
            te_im=imdct(width+1:width+8,height+1:height+8);
            %%%%%%%%%%
             
            if orcof>imdct(width+em_cof(kk,1),height+em_cof(kk,2))         
               imdct(width+em_cof(kk,1),height+em_cof(kk,2))=imdct(width+em_cof(kk,1),height+em_cof(kk,2))-qstep;
            else
              imdct(width+em_cof(kk,1),height+em_cof(kk,2))=imdct(width+em_cof(kk,1),height+em_cof(kk,2))+qstep;  
            end       
         end
         l=l+1;
         end
         
        width=(i-1)*16+8;
        height=(j-1)*8;
         for kk=4:NN  
         qstep=Q_table(em_cof(kk,1),em_cof(kk,2))+1;
         orcof=imdct(width+em_cof(kk,1),height+em_cof(kk,2));
         imdct(width+em_cof(kk,1),height+em_cof(kk,2))=round(orcof/qstep)*qstep;
            if mod(round(imdct(width+em_cof(kk,1),height+em_cof(kk,2))/qstep),2)~=Q(l)
            err=err+1;
            
               %%%%%%%%%
            te_im=imdct(width+1:width+8,height+1:height+8);
            %%%%%%%%%%
            if orcof>imdct(width+em_cof(kk,1),height+em_cof(kk,2))         
               imdct(width+em_cof(kk,1),height+em_cof(kk,2))=imdct(width+em_cof(kk,1),height+em_cof(kk,2))-qstep;
            else
              imdct(width+em_cof(kk,1),height+em_cof(kk,2))=imdct(width+em_cof(kk,1),height+em_cof(kk,2))+qstep;  
            end       
         end
         l=l+1;
         end
         
         k=k+1;
   end
end

if err<=0
break;
end

for i=1:(m/8);
    for j=1:(n/8);
        width=(i-1)*8+1;
        height=(j-1)*8+1;
        watermarked(width:(width+7),height:(height+7))=idct2(imdct(width:(width+7),height:(height+7)));
    end
end
watermarked=double(uint8(round(watermarked)));

end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -