论文部分程序仿真代码

designed by lilizong
lilizong[at]gmail
实验仿真部分代码
row=1;
col=1;
%控制最终显示窗口中显示的图像行列数
myinforarray=linspace(0,0,5);
mypsnrarray=linspace(0,0,5);
w=1;
for myouter=1:1      %此处设置迭代次数,多次迭代可以计算优化效果
    A=imread('e:oat.bmp');
    %     subplot(row,col,[1 2 4 5 7 8]),imshow(A),title('原始载体图像');
    %     subplot(row,col,1),imshow(A),title('原始载体图像');
    [m,n]=size(A);
    B=cell(8,8);%这里的k为你要分成大小为k*k的块
    AA=A;
    myinfor=0;
    for myinter=1:1  %此处设置插值次数

        for i=1:512/8
            for j=1:512/8
                B{i,j}=A((i-1)*8+1:i*8,(j-1)*8+1:j*8);
            end
        end


        %将B化为一维
        c=cell(8,8);
        k=1;
        for i=1:512/8
            for j=1:512/8
                c{k}=B{i,j};
                k=k+1;
            end
        end

        %下面的代码用于生成混沌序列,生成4096个数字,然后排序
        %得到一个位于4096之间的无重复值的混沌序列

        x=linspace(0,0,4096);

        x(1)=0.75+0.001+myinter/10+myouter/1000;
        % 0.73得值获得好结果,其他结果不佳
        t=linspace(0,0,4096);
        m=0;
        n=0;
        for i=1:4095
            x(i+1)=1-2*x(i)*x(i);
            k=k+1;
        end

        [pm,pn]=sort(x);
        %pn为排序后结果,pm为原始数列

        tod=cell(8,8);
        %定义tod为需要处理的图像块
        for  i=1:4096
            tod{i}=c{pn(i)};

            test=tod;    %添加一个测试块,看看问题出现在什么地方
        end
        %对图像进行拼接,显示一下置乱后的图像
        toad=cell(8,8);
        for i=1:4096
            toad{i}=tod{i};
        end
        k=1;
        toyuan=cell(8,8);
        for i=1:64
            for j=1:64
                toyuan{i,j}=toad{k};
                k=k+1;
            end
        end


        toyuan=cell2mat(toyuan);

        %             subplot(row,col,2),imshow(toyuan),title('分块置乱后载体图像');

        %temp=cell(8,8);
        %得到像素值数组xiang
        xiangsu=linspace(0,0,256);
        %对取得的图像快进行分析,找到最大像素值
        for m=1:4096
            temp=tod{i};
            %   temp=cell2mat(temp);
            for i=1:8
                for j=1:8
                    for  n=1:256
                        if temp(i,j)==n
                            xiangsu(n)=xiangsu(n)+1;
                        end
                    end
                end
            end
        end
        %求出最大像素的值
        maxxiangsu=xiangsu(1);
        for i=1:256
            if maxxiangsu
< xiangsu (i)
                maxxiangsu
=xiangsu(i);
                
maxvalueofxiangsu =i;
            
end
        end

        maxvalueofxiangsu;
        %开始对需要嵌入信息的图像快进行移位处理
        for m
=1:4096   %表示需要处理的块数
            temp
=tod{m};
            
for i =1:8
                
for j =1:8
                    
if temp(i,j)<maxvalueofxiangsu
                        %temp(i,j)
=maxvalueofxiangsu-1;
                        
temp(i,j) =temp(i,j)-1;
                    
end
                end

            end
            %tod{m}
=mat2cell(temp);   更改4.28
            tod{m}
=temp;
        
end
        %处理完毕,开始嵌入水印

        %读入水印信息

        b
=imread('e:logo1.bmp');
        
b =im2bw(b);
        
[p,q] =size(b);
        
oo =p*q;   %用来标识水印的总像素数

        %         watermark
=reshape(b,1,oo);

        
watermark =zeros(1,oo);

        
n =1;
        
for i =1:p
            
for j =1:q
                
watermark(n) =b(i,j);
                
n =n+1;
            
end
        end
        %         subplot(row,col,6),imshow(b),title('水印图像');
        watermark;
        waterlogistic
=zeros(1,1600);
        
waterlogistic(1) =0.8;
        
for i =2:1600
            
waterlogistic(i) =1-2*waterlogistic(i-1)*waterlogistic(i-1);
        
end

        for i
=1:1600
            
if  waterlogistic(i) > 0
                waterlogistic(i)=1;
            else
                waterlogistic(i)=0;
            end
        end

        waterlogistic;

        watermark=xor(watermark,waterlogistic);
        n=1;
        for i=1:40
            for j=1:40
                towatermark(i,j)=watermark(n);
                n=n+1;
            end
        end


        %         subplot(row,col,8),imshow(towatermark),title('加密后水印图像');



        yuanwatermark=xor(watermark,waterlogistic);
        n=1;
        for i=1:40
            for j=1:40
                yuanwatermark1(i,j)=yuanwatermark(n);
                n=n+1;
            end
        end

        %         subplot(row,col,10),imshow(yuanwatermark1),title('测试:恢复后水印图像');
        %嵌入方式为,找到最高位,如果水印为0,不发生变化,如果水印为1,最高位减1
        %令tt为嵌入水印循环量,如果t的值超过水印的信息量,则开始进行新的循环。
        t=1;             %用来标识嵌入位
        infor=0;         %用来标识总共可以嵌入的信息
        for m=1:4096
            % temp=cell2mat(toa{m});
            temp=tod{m};
            for i=1:8
                for j=1:8
                    if temp(i,j)==maxvalueofxiangsu
                        if watermark(t)==1   %水印的信息如果是1,则进行原信息的改变
                            temp(i,j)=temp(i,j)-1;  %此处测试一下
                            %  temp(i,j)=256;
                        end
                        t=t+1;
                       if t==1600
                           t=1;
                       end
                        infor=infor+1;
                    end
                end
            end
            %tod{m}=mat2cell(temp);
            tod{m}=temp;
        end
        myinfor=myinfor+infor;

        %对图像进行拼接,显示一下添加水印以后的图像
        toad=cell(8,8);
        for i=1:4096
            toad{i}=tod{i};
        end
        k=1;
        toyuan=cell(8,8);
        for i=1:64
            for j=1:64
                toyuan{i,j}=toad{k};
                k=k+1;
            end
        end
        toyuan=cell2mat(toyuan);
%         subplot(row,col,1),imshow(toyuan),title('添加水印后的置乱图像');
        %对图像进行拼接,显示添加水印后原始图像效果
        toad=cell(8,8);
        for i=1:4096
            toad{pn(i)}=tod{i};
        end
        k=1;
        toyuan=cell(8,8);
        for i=1:64
            for j=1:64
                toyuan{i,j}=toad{k};
                k=k+1;
            end
        end


        toyuan=cell2mat(toyuan);


%         subplot(row,col,2),imshow(toyuan),title('测试:加水印后原始图像');
        % figure,imshow(toyuan);
        %  此处请屏蔽外层循环后开启!!!!!
        A=toyuan;
    end
    %%%%%以下为提取水印过程
        %开始读取水印
    %1 首先将嵌入水印后图像按照加密过程进行置乱,并从中提取嵌入到其中的加密后的水印信息
    %2 对提取出来的加密后的水印与混沌徐序列进行相与操作,得到原始水印图像
    B=cell(8,8);%这里的k为你要分成大小为k*k的块
    AA=A;
    myinfor=0;
    for myinter=1:1  %此处设置插值次数

        for i=1:512/8
            for j=1:512/8
                B{i,j}=A((i-1)*8+1:i*8,(j-1)*8+1:j*8);
            end
        end
        %将B化为一维
        c=cell(8,8);
        k=1;
        for i=1:512/8
            for j=1:512/8
                c{k}=B{i,j};
                k=k+1;
            end
        end
    x=linspace(0,0,4096);

    x(1)=0.75+0.001+myinter/10+myouter/1000;
    % 0.73得值获得好结果,其他结果不佳
    t=linspace(0,0,4096);
    m=0;
    n=0;
    for i=1:4095
        x(i+1)=1-2*x(i)*x(i);
        k=k+1;
    end

    [pm,pn]=sort(x);
    %pn为排序后结果,pm为原始数列

    tod=cell(8,8);
    %定义tod为需要处理的图像块
    for  i=1:4096
        tod{i}=c{pn(i)};

        test=tod;    %添加一个测试块,看看问题出现在什么地方
    end
watermark=zeros(1,1600);
n=1;
 for m=1:4096
            % temp=cell2mat(toa{m});
            temp=tod{m};
            for i=1:8
                for j=1:8
                    if temp(i,j)==maxvalueofxiangsu
                    watermark(n)=0;
                    n=n+1;
                    end
                    if temp(i,j)==maxvalueofxiangsu-1
                        watermark(n)=1;
                        n=n+1;
                    end
                    
                        infor=infor+1;
                    end
                end
            end
            %tod{m}=mat2cell(temp);
            tod{m}=temp;
    end
        towatermark=zeros(40,40);
n=1;
       for i=1:40
            for j=1:40
                towatermark(i,j)=watermark(n);
                n=n+1;
            end
        end

%     subplot(row,col,2),imshow(towatermark),title('测试:加水印后原始图像');

watermark2=zeros(1,1600);
for i=1:1600
    watermark2(i)=watermark(i);
end


towatermark=xor(watermark2,waterlogistic);

        towatermark2=zeros(40,40);

n=1;
       for i=1:40
            for j=1:40
                towatermark2(i,j)=towatermark(n);
                n=n+1;
            end
        end
    subplot(row,col,1),imshow(towatermark2),title('提取水印图像');

    %%%%%  以上为提取水印过程
    %      figure,imshow(toyuan),title('加载了隐藏信息的图片');
    %toyuan
    %上述语句用于显示每次加密后的载体图片
    x=AA;
    x1=toyuan;
    x=double(x);
    x1=double(x1);
    for i=1:256;
        for j=1:256;
            MYa(i,j)=x(i,j)^2;  %after filtering's single
            MYb(i,j)=x(i,j)-x1(i,j);
        end
    end
    d=0;
    e=0;
    for i=1:256;
        for j=1:256;
            d=d+MYa(i,j);
            e=e+MYb(i,j)*MYb(i,j);
        end
    end
    f=log10(d/e);
    g=10*f ;
    %下面开始同时他的信息值和psnr值
    myinforarray(w)=myinfor;
    mypsnrarray(w)=uint8(g);
    w=w+1;


end
%myinter
%for i=1:myouter


%myinforarray
%mypsnrarray
%figure,plot(myinforarray);
%figure,plot(mypsnrarray);


%myinforarray
%mypsnrarray

你可能感兴趣的:(c,加密,测试,OO,Gmail,plot)