| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1269 人关注过本帖
标题:请教matlab抵抗旋转攻击的水印提取代码
取消只看楼主 加入收藏
wjp1226
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-30
收藏
 问题点数:0 回复次数:0 
请教matlab抵抗旋转攻击的水印提取代码
在pudn上下载了一个代码,发现提取水印的代码都是限定了图片的大小,如果图片的大小改变了代码就会报错。而进行旋转攻击后图片的大小是要改变的,请问这时候怎么提取水印啊?

  谁有能抵抗旋转攻击的水印植入和提取代码啊?讲一讲原理也好。




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function averagemark=putout(X,Y)
%函数作用:对含水印图象,用原始图象比较然后提取出水印
%输入变量:X,原始图象的像素值,Y,嵌入水印后的图象
%输出变量:averagemark,提取的水印图象求的平均
%实验不妨固定小波包变换结构为:

%1    2    5    6        13    14
%3    4    7    8        15    16
%9    10        17    18    
%11    12        19    20    
%21    22            
%23    24            
%    25    26        
%    27    28        

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function averagemark=putout(X,Y)
%对原始图象进行小波包变换(实验用固定结构的小波包变换,没有使用验证密码来随机改变这个小波包的%变换结构)
%把X进行三次小波变换,小波基为db1
%一级小波包变换
[ca1,ch1,cv1,cd1]=dwt2(X,'db1');
%二级小波包变换
[ca1_a,ca1_h,ca1_v,ca1_d]=dwt2(ca1,'db1');
[ch1_a,ch1_h,ch1_v,ch1_d]=dwt2(ch1,'db1');
[cv1_a,cv1_h,cv1_v,cv1_d]=dwt2(cv1,'db1');
[cd1_a,cd1_h,cd1_v,cd1_d]=dwt2(cd1,'db1');
%三级小波包变换
[ca1_aa,ca1_ah,ca1_av,ca1_ad]=dwt2(ca1_a,'db1');
[ca1_ha,ca1_hh, ca1_hv, ca1_hd]=dwt2(ca1_h,'db1');
[ca1_va,ca1_vh, ca1_vv, ca1_vd]=dwt2(ca1_v,'db1');
[ch1_ha,ch1_hh, ch1_hv, ch1_hd]=dwt2(ch1_h,'db1');
[ch1_va,ch1_vh, ch1_vv, ch1_vd]=dwt2(ch1_v,'db1');
[cv1_aa,cv1_ah, cv1_av, cv1_ad]=dwt2(cv1_a,'db1');
[cv1_da,cv1_dh, cv1_dv, cv1_dd]=dwt2(cv1_d,'db1');
%组织每块小波块,并标上序号
W1= ca1_aa;
W2=ca1_ah;
W3= ca1_av;
W4=ca1_ad;
W5=ca1_ha;
W6=ca1_hh;
W7=ca1_hv;
W8=ca1_hd;
W9=ca1_va;
W10=ca1_vh;
W11=ca1_vv;
W12=ca1_vd;
W13=ch1_ha;
W14=ch1_hh;
W15=ch1_hv;
W16=ch1_hd;
W17=ch1_va;
W18=ch1_vh;
W19=ch1_vv;
W20=ch1_vd;
W21=cv1_aa;
W22=cv1_ah;
W23=cv1_av;
W24=cv1_ad;
W25=cv1_da;
W26=cv1_dh;
W27=cv1_dv;
W28=cv1_dd;
W=[W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13 W14 W15 W16 W17 W18 W19 W20 W21 W22 W23 W24 W25 W26 W27 W28];
%对小波块进行模糊分类
%首先对纹理强度模糊分类
%首先计算每个小波块中小波系数大于1的像素数目,记录在number中
for k=0:27
    temp=W(1:32,32*k+1:32*k+32);
    num=0;
    for i=1:32
         for j=1:32
             if temp(i,j)>0
                num=1+num;
              end
          end
      end
       %number(k+1)=num;
       % end
 
%计算每块小波系数的隶属度
      %计算对small的隶属度A_small
      if num<=400
         A_small=1;
      end
         if (num>400)&(num<=450)
            A_small=(450-num)/(450-400);
        end
          if (num>450)
             A_small=0;
          end
     
%计算对middle的隶属度A_middle
      if num<=400
         A_middle=0;
      end
      if (num>400)&( num<=450)
         A_middle =(num-400)/(450-400);
      end
       if (num>450)&( num<=500)
         A_middle =1;
      end
       if (num>500)&( num<=550)
         A_middle =(550-num)/(550-500);
      end
      if num>500
        A_middle=0;
        end
%计算对big的隶属度A_big
      if num<=500
         A_big=0;
     end
          if (num>500)&(num<=550)
            A_big=(num-500)/(550-500);
          end
          if (num>550)
             A_big=1;
          end

%得到模糊分类的结果.返回的结果1代表是small,2代
%表是middle,3代表是big;
if A_small==max([A_small;A_middle;A_big])
         fuzzy_result_Texture(k+1)=1;
end
if A_middle==max([A_small;A_middle;A_big])
         fuzzy_result_Texture(k+1)=2;
end
if A_big==max([A_small;A_middle;A_big])
        fuzzy_result_Texture(k+1)=3;
end
end
%对每个小波块进行能量大小的模糊分类。
%(1)计算每个小波块的能量,值存在e中
e=zeros(1,28);
for k=0:27
temp=W(1:32,32*k+1:32*k+32);
sum=0;
    for i=1:32
         for j=1:32
             sum=temp(i,j)^2+sum;
          end
      end
      e(1+k)=sum;
 end
%(2)对每个小波块的能量按小到大排列得到排名号
%注:最大为28号,最小为1号。排名号存在变量paiming
%中
paiming=zeros(1,28);
for i=1:28
   for j=i+1:28
     if e(i)<=e(j)
        s=0; t=1;
     else
        s=1; t=0;
      end
   paiming(i)=paiming(i)+s;
   paiming(j)=paiming(j)+t;
end
end
paiming=paiming+1;
%计算每块小波块的隶属度
%计算对small的隶属度B_small
for i=1:28
      if paiming(i)<=5
         B_small(i)=1;
      end
      if (paiming(i)>5)&(paiming(i)<=10)
            B_small(i)=(10-paiming(i))/(10-5);
        end
        if paiming(i)>10
             B_small(i)=0;
        end

end
%计算对middle的隶属度B_middle
for i=1:28
      if paiming(i)<=5
         B_middle(i)=0;
      end
       if (paiming(i)>5)&( paiming(i)<=10)
         B_middle(i) =(paiming(i)-5)/(10-5);
      end
       if (paiming(i)>10)&( paiming(i)<=15)
         B_middle(i) =1;
      end
       if (paiming(i)>15)&( paiming(i)<=20)
         B_middle(i) =(20- paiming(i))/(20-15);
      end
      if paiming(i)>20
        B_middle(i)=0;
       end
end
%计算对big的隶属度B_big
for i=1:28
      if paiming(i)<=15
         B_big(i)=0;
     end
      if (paiming(i)>15)&( paiming(i)<=20)
            B_big(i)=(paiming(i)-15)/(20-15);
      end
      if paiming(i)>20
             B_big(i)=1;
      end

end
%得到模糊分类的结果.返回的结果1代表是small,2代
%表是middle,3代表是big;
for i=1:28
if B_small(i)==max([B_small(i);B_middle(i);B_big(i)])
         fuzzy_result_Energy(i)=1;
end
if B_middle(i)==max([B_small(i);B_middle(i);B_big(i)])
         fuzzy_result_Energy(i) =2;
end
if B_big(i)==max([B_small(i);B_middle(i);B_big(i)])
        fuzzy_result_Energy(i) =3;
end
end
%根据模糊规则得到最后的分类结果,存在变量B中,1代%表small,3代表big
for i=1:28
if (fuzzy_result_Texture(i)==3)&( fuzzy_result_Energy(i)==1)
B(i)=3;
end
if (fuzzy_result_Texture(i)==3)&( fuzzy_result_Energy(i)==2)
B(i)=2;
end
if (fuzzy_result_Texture(i)==3)&( fuzzy_result_Energy(i)==3)
B(i)=1;
end
if (fuzzy_result_Texture(i)==2)&( fuzzy_result_Energy(i)==3)
B(i)=1;
end
if (fuzzy_result_Texture(i)==2)&( fuzzy_result_Energy(i)==2)
B(i)=2;
end
if (fuzzy_result_Texture(i)==2)&( fuzzy_result_Energy(i)==1)
B(i)=2;
end
if (fuzzy_result_Texture(i)==1)&( fuzzy_result_Energy(i)==3)
B(i)=2;
end
if (fuzzy_result_Texture(i)==1)&( fuzzy_result_Energy(i)==2)
B(i)=1;
end
if (fuzzy_result_Texture(i)==1)&( fuzzy_result_Energy(i)==1)
B(i)=3;
end
end

%根据B中的值得到相应的水印嵌入强度,存放在 q中
for i=1:28
if B(i)==1
   q(i)=0.06;
end
if B(i)==2
   q(i)=0.11;
end
if B(i)==3
   q(i)=0.15;
end
end

%对含水印图象也做三次小波变换,然后分出小波块
%把Y进行同样的三次小波变换,小波基为db1
%一级小波包变换
[hca1,hch1,hcv1,hcd1]=dwt2(Y,'db1');
%二级小波包变换
[hca1_a,hca1_h,hca1_v,hca1_d]=dwt2(hca1,'db1');
[hch1_a,hch1_h,hch1_v,hch1_d]=dwt2(hch1,'db1');
[hcv1_a,hcv1_h,hcv1_v,hcv1_d]=dwt2(hcv1,'db1');
%三级小波包变换
[hca1_aa,hca1_ah,hca1_av,hca1_ad]=dwt2(hca1_a,'db1');
[hca1_ha,hca1_hh,hca1_hv, hca1_hd]=dwt2(hca1_h,'db1');
[hca1_va,hca1_vh, hca1_vv, hca1_vd]=dwt2(hca1_v,'db1');
[hch1_ha,hch1_hh, hch1_hv, hch1_hd]=dwt2(hch1_h,'db1');
[hch1_va,hch1_vh, hch1_vv, hch1_vd]=dwt2(hch1_v,'db1');
[hcv1_aa,hcv1_ah, hcv1_av, hcv1_ad]=dwt2(hcv1_a,'db1');
[hcv1_da,hcv1_dh, hcv1_dv, hcv1_dd]=dwt2(hcv1_d,'db1');
%组织每块小波块,并标上序号
HW1= hca1_aa;
HW2=hca1_ah;
HW3= hca1_av;
HW4=hca1_ad;
HW5=hca1_ha;
HW6=hca1_hh;
HW7=hca1_hv;
HW8=hca1_hd;
HW9=hca1_va;
HW10=hca1_vh;
HW11=hca1_vv;
HW12=hca1_vd;
HW13=hch1_ha;
HW14=hch1_hh;
HW15=hch1_hv;
HW16=hch1_hd;
HW17=hch1_va;
HW18=hch1_vh;
HW19=hch1_vv;
HW20=hch1_vd;
HW21=hcv1_aa;
HW22=hcv1_ah;
HW23=hcv1_av;
HW24=hcv1_ad;
HW25=hcv1_da;
HW26=hcv1_dh;
HW27=hcv1_dv;
HW28=hcv1_dd;
HW=[HW1 HW2 HW3 HW4 HW5 HW6 HW7 HW8 HW9 HW10 HW11 HW12 HW13 HW14 HW15 HW16 HW17 HW18 HW19 HW20 HW21 HW22 HW23 HW24 HW25 HW26 HW27 HW28];
%比较每个小波块的差别,把每块的差别存在difference变量中
difference=HW-W;
%从difference中求出嵌入的每块水印的平均值
sum=zeros(32,32);
for i=0:27
   temp=difference(1:32,32*i+1:32*i+32);
   temp=temp/q(1,i+1);
   sum=sum+temp;
end
averagemark=sum/28;
搜索更多相关主题的帖子: 水印 matlab 图象 代码 变量 
2008-06-30 16:18
快速回复:请教matlab抵抗旋转攻击的水印提取代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044247 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved