465393227 发表于 2012-5-4 19:39

各位高手帮我调试一下,LSB程序问题求助

本帖最后由 465393227 于 2012-5-4 19:40 编辑

这个程序错漏百出,求高手调试
function =lsb(attack_style,weizhi,attack_strength)
%%% attack_style 用于设置选择何种攻击
%%% weizhi 用于在广义LSB中设置修改的为平面
%%% err 返回误码率
%%% psnr 返回峰值信噪比
%%% attack_strength 用于控制攻击的强弱

clc

%%%%%%%%%%%%%%%% 读入原始载体图像 %%%%%%%%%%%%%%%%%%%%%%%%%%%
=imread('lena.bmp');
=size(x);
M=row;
N=col;
MN=col*row;
figure(1),imshow(uint8(x));%%; image(x), colormap(map);
title('原始图像','Fontsize',16,'color','blue');
x_source=x;
%%%%%%%%%%%%%%%% 读入原始水印 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
=imread('laugh-single.bmp');
for i=1:256
    for j=1:256
      if double(m(i,j))==0
            w(i,j)=0;
      else
            w(i,j)=1;
      end
    end
end
%%%%%%%%%%%%%%%% 水印信息的嵌入 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
s=x;
for i=1:256
    for j=1:256
      s(i,j)=bitset(x(i,j),weizhi,w(i,j));
    end
end
imwrite(s,'lsb_watermarked.bmp');
figure(2),imshow(uint8(s));
%%%%%%%%%%%%%%%% 计算峰值信噪比PSNR %%%%%%%%%%%%%%%%%%%%%%%%
x_temp1=double(s)-double(x_source);
figure(3),imshow(uint8(round(100*x_temp1)));
imwrite((uint8(round(100*x_temp1))),'LSB_chazhi.bmp');
x_temp2=x_temp1( : );
x_temp3=abs(x_temp2);
x_temp4=x_temp3'*x_temp3;
d_embed=x_temp4/(M*M);
SDR1=255*255/d_embed;
psnr=10*log10(SDR1);
%%%%%%%%%%%%%%%% 攻击 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s=imread('LSB_watermarked.bmp');
J2=s;
if attack_style==1
    %%放大两倍操作(提取前先缩小两倍)
    xxx1=imresize(J2,2,'bicubic');
    xxx2=imresize(xxx1,1/2,'bicubic');
    yy=double(xxx2);
end
if attack_style==2
    %%放大4倍操作(提取前先缩小4倍)
    xxx1=imresize(J2,4,'bicubic');
    xxx2=imresize(xxx1,1/4,'bicubic');
    yy=double(xxx2);
end
if attack_style==3
    %%缩小1/4操作
    xxx1=imresize(J2,3/4,'bicubic');
    xxx2=imresize(xxx1,4/3,'bicubic');
    yy=double(xxx2);
end
if attack_style==4
    %%
    xxx1=imresize(J2,2/4,'bicubic');
    xxx2=imresize(xxx1,4/2,'bicubic');
    yy=double(xxx2);
end
%%3*3空域低通滤波
if attack_style==5
    B=(1/9)*ones(3,3);
    xxx2=filter2(B,J2);
    yy=double(xxx2);
end
%%4领域平均
if attack_style==6
    B=*(1/4);
    xxx2=filter2(B,J2);
    yy=double(xxx2);
end
%%8领域平均
if attack_style==7
    B=*(1/8);
    xxx2=filter2(B,J2);
    yy=double(xxx2);
end
%%窗口中值滤波
if attack_style==8
    xxx2=medfilt2(J2); %默认3*3
    yy=double(xxx2);
end
if attack_style==9
    % a1=input('Please input length of window a1:');
    % b1=input('Please input length of window b1:');
    a1=1;
    b1=3;
    xxx2=medfilt2(J2,);
    save al al;
    save b1 b2;
    yy=double(xxx2);
end
%% 裁减
if attack_style==10
    for i=128-44:128+45
      for j=128-45:128+44
            J2(i,j)=0;
      end
    end
    yy=double(J2);
end
if attack_style==11
    for i=128-64:128+63
      for j=128-64:128+63
            J2(i,j)=0;
      end
    end
    yy=double(J2);
end
if attack_style==12
    yy=imnoise(uint8(round(J2)),'gaussian',0,attack_strength); %高斯噪声
end
if attack_style==13
    imwrite(uint8(round(J2)),'jpeg_n.jpg','jpg','Quality',attack_strength);
    =imread('jpeg_n.jpg','jpg');
end
if attack_style>13
    yy=J2;
end
%%%%%%%%%%%%%%%%%%%%% 水印提取 %%%%%%%%%%%%%%%%%
for i=1:256
    for j=1:256
      mm(i,j)=bitget(uint8(yy(i,j)),weizhi);
      if double(mm(i,j))==1
            mm(i,j)=255;
      else
            mm(i,j)=0;
      end
    end
end
%%%%%%%%%%%%%% 计算误码率 %%%%%%%%%%%%%%%%%%%]
err=sum(sum(xor(m,mm)))/(256*256);

465393227 发表于 2012-5-4 19:41

附件已经上传,下载完可以直接调试,求助{:{19}:}{:{19}:}{:{19}:}
页: [1]
查看完整版本: 各位高手帮我调试一下,LSB程序问题求助