zoukankan      html  css  js  c++  java
  • 数字水印的嵌入

    代码是用matlab写的

    基于空域的最低有效位替换算法(LSBR)

    采用LSBR,将秘密分别顺序隐藏到rgb图像的r、g、b各个层,将秘密的每一位嵌入到载体各像素的最低的一位
    载体

    秘密

    含有秘密的载体

    提取的秘密

    隐藏代码:

    cover=imread('C:UsersDesktopc.bmp');
    secret=imread('C:UsersDesktops.bmp');
    coverr=cover(:,:,1);
    coverg=cover(:,:,2);
    coverb=cover(:,:,3);
    [p,q]=size(secret);
    p=uint32(p);
    q=uint32(q);
    for i=1:p
        for j=1:q
            switch(mod(j,3))
                case 1
                    coverr(i,j)=bitor(bitshift       (bitshift(coverr(i,j),-1),1)     ,uint8(secret(i,j)));
                case 2
                    coverg(i,j)=bitor(bitshift       (bitshift(coverg(i,j),-1),1)     ,uint8(secret(i,j)));
                case 0
                    coverb(i,j)=bitor(bitshift       (bitshift(coverb(i,j),-1),1)     ,uint8(secret(i,j)));
            end
        end
    end
    imwrite(cat(3,coverr,coverg,coverb),'C:UsersDesktopste.bmp');
    

    提取代码:

    ste=imread('C:UsersDesktopste.bmp');
    ster=ste(:,:,1);
    steg=ste(:,:,2);
    steb=ste(:,:,3);
    s=[256,256];
    for i=1:256
        for j=1:256
            switch(mod(j,3))
                case 1
                    s(i,j)=bitshift(bitshift(ster(i,j),7),-7);
                case 2
                    s(i,j)=bitshift(bitshift(steg(i,j),7),-7);
                case 0
                    s(i,j)=bitshift(bitshift(steb(i,j),7),-7);
            end
        end
    end
    imwrite(s,'C:UsersDesktopsecret.bmp');
    

    Jsteg算法的实现

    在JPEG图像的DCT系数上进行LSB替换,实现秘密信息的嵌入
    Jpg的图像相比bmp隐写容量更小,开始选的256*256的图像就不能完全嵌入。在量化后的dct系数上嵌入时要注意dc系数不嵌,0与1也不嵌。
    载体

    秘密

    含有秘密的载体

    提取的秘密

    嵌入代码:

    cover=jpeg_read('C:UsersDesktopc.jpg');
    secret=imread('C:UsersDesktop	.bmp');
    secret1=reshape(secret,1,[]);
    [p,q]=size(cover.coef_arrays{1,1});
    p=uint32(p);
    q=uint32(q);
    %cover1=reshape(cover.coef_arrays{1,1},1,[]);
    %hist(cover1,20);
    num=1;
    for i=1:p
        for j=1:q 
            if(num==64*64+1)
                break;
            else
                if ( mod(i,8) == 1 && mod(j,8) == 1)
                    continue;
                elseif (cover.coef_arrays{1,1}(i,j) == 0)
                    continue;
                elseif(cover.coef_arrays{1,1}(i,j) == 1)
                    continue;
                else
                    cover.coef_arrays{1,1}(i,j) = cover.coef_arrays{1,1}(i,j) - mod(cover.coef_arrays{1,1}(i,j), 2) + secret1(num);
                    num=num+1;
                end
            end
        end
    end
    jpeg_write(cover,'C:UsersDesktopste.jpg');
    

    提取代码:

    cover=jpeg_read('C:UsersDesktopste.jpg');
    [p,q]=size(cover.coef_arrays{1,1});
    %ste=reshape(cover.coef_arrays{1,1},1,[]);
    %hist(ste,20);
    p=uint32(p);
    q=uint32(q);
    num=1;
    for i=1:p
        for j=1:q 
            if(num==64*64+1)
                break;
            else
                if ( mod(i,8) == 1 && mod(j,8) == 1)
                    continue;
                elseif (cover.coef_arrays{1,1}(i,j) == 0)
                    continue;
                elseif(cover.coef_arrays{1,1}(i,j) == 1)
                    continue;
                else
                    secret(num) = mod(cover.coef_arrays{1,1}(i,j), 2);
                    num=num+1;
                end
            end
        end
    end
    secret1=reshape(secret,[64,64]);
    imwrite(secret1,'C:UsersDesktopsecretste.bmp');
    

    隐写分析方法—卡方统计分析

    在上一步jsteg嵌入和提取代码中分别加入下面代码即可:
    cover1=reshape(cover.coef_arrays{1,1},1,[]);
    hist(cover1,20);
    ste=reshape(cover.coef_arrays{1,1},1,[]);
    hist(ste,20);
    因为在嵌入时选择的图像过小,卡方分析可能效果不明显。但当时选大了,又嵌不进去。
    对载体的统计直方图:

    对含有秘密的载体的统计直方图:

  • 相关阅读:
    在tableViewCell上添加button导致按钮没有点击效果和不能滑动
    jquery添加自定义校验
    json转化对特殊字段的处理
    模仿spring authentication-provider 自己写登录人管理
    hibernate自动建表
    java 上传文件
    java实现赋值excel模板,并在新文件中写入数据,并且下载
    实现图片预览
    ajax+jquery实现父页面弹出子页面,选择提交后给父页面传值
    上传附件,压缩并加密
  • 原文地址:https://www.cnblogs.com/Qi-Lin/p/12218688.html
Copyright © 2011-2022 走看看