声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1261|回复: 1

[图像处理] 各位高手帮我调试一下,LSB程序问题求助

[复制链接]
发表于 2012-5-4 19:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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

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

clc

%%%%%%%%%%%%%%%% 读入原始载体图像 %%%%%%%%%%%%%%%%%%%%%%%%%%%
[x,map]=imread('lena.bmp');
[row,col]=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;
%%%%%%%%%%%%%%%% 读入原始水印 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m,mapm]=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=[0 1 0;1 0 1;0 1 0]*(1/4);
    xxx2=filter2(B,J2);
    yy=double(xxx2);
end
%%8领域平均
if attack_style==7
    B=[1 1 1;1 0 1;1 1 1]*(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,[a1 b1]);
    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);
    [yy,map]=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);
lsb.rar (108.35 KB, 下载次数: 0)
回复
分享到:

使用道具 举报

 楼主| 发表于 2012-5-4 19:41 | 显示全部楼层
附件已经上传,下载完可以直接调试,求助
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 04:30 , Processed in 0.067686 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表