F4信息隐藏算法

目录

  • 实验环境
  • 系统设计
      • F4信息隐藏算法替换规则
      • 嵌入算法
      • 提取算法
  • 系统实现
    • 嵌入算法
      • F4_simulation.m
      • stego.m
    • 提取算法
      • F4_extract.m
      • extract.m
  • 实验结果
    • 信息嵌入
    • 信息提取
    • 信息比对
  • 参考文献

实验环境

  • MATLAB
  • 从JPEG图片中提取DCT系数的程序jpeg_toolbox,下载地址为http://dde.binghamton.edu/download/jpeg_toolbox.zip。

程序来源:Simulator of nsF5 embedding (Matlab):http://dde.binghamton.edu/download/nsf5simulator/。

封装包名称与操作系统的对应关系如下:
mexa64 -> 64-bit Linux
mexglx -> 32-bit Linux
mexw32 -> 32-bit Windows
mexw64 -> 64-bit Windows

系统设计

       F3信息隐藏算法的替换规则将会使得载密图像的DCT系数中的偶系数增多。
       F4信息隐藏算法改进了F3信息隐藏算法中用到的替换规则,解决了这个问题。
       F4信息隐藏算法嵌入过程的关键步骤就是将原始图像的AC系数中最低的一个位平面“替换”为要隐藏的秘密信息。这里的“替换”遵循如下规则:
       (1)跳过0;
       (2)若AC系数为2i,且i>=0,秘密比特为0,该系数不变;
       (3)若AC系数为2i,且i>=0,秘密比特为1,该系数变为2i-1;
       (4)若AC系数为2i,且i<0,秘密比特为0,该系数变为2i+1;
       (5)若AC系数为2i,且i<0,秘密比特为1,该系数不变;
       (6)若AC系数为2i+1,且i>=0,秘密比特为0,该系数变为2i;
       (7)若AC系数为2i+1,且i>=0,秘密比特为1,该系数不变;
       (8)若AC系数为2i+1,且i<0,秘密比特为0,该系数不变;
       (9)若AC系数为2i+1,且i<0,秘密比特为1,该系数变为2i+2;
       (10)若AC系数变为0,则该秘密比特需要重新隐藏。

F4信息隐藏算法替换规则

F4信息隐藏算法_第1张图片
       由此规则可知:载密图像的AC系数中,0不包含任何秘密信息(或无需恢复)。此外,其他大于0的AC系数中的最低比特位为秘密比特,小于0的AC系数中的最低比特位取反后为秘密比特。只需将除0外的其他大于0的AC系数中的最低比特位取出,将除0外的其他小于0的AC系数中的最低比特位取出后取反,即可恢复秘密信息。
       换句话说,载密图像的AC系数中,除0外,正奇数和负偶数代表1正偶数和负奇数代表0

嵌入算法

       F4信息隐藏算法嵌入流程如下:
       (1)提取原始图像的DCT系数,获取AC系数;
       (2)将秘密信息转换为二进制序列,并按照F4信息隐藏算法替换规则,将原始图像中AC系数的最低比特位替换为二进制序列中的每一比特信息;
       (3)在替换过程结束后,将像素点的二进制数据转换回十进制数据,保存为载密图像。

提取算法

       与嵌入算法对应,F4信息隐藏算法提取流程如下:
       (1)提取载密图像的DCT系数,获取AC系数;
       (2)将除0外的其他大于0的AC系数中的最低比特位取出,将除0外的其他小于0的AC系数中的最低比特位取出后取反,即可恢复秘密信息,根据嵌入顺序进行组合得到原秘密序列。

系统实现

嵌入算法

F4_simulation.m

function [nzAC] = F4_simulation(COVER, STEGO, message)

try
    jobj = jpeg_read(COVER); %读取cover图片
    PrimeDCT = jobj.coef_arrays{1}; %读取DCT系数
    DCT = PrimeDCT;
catch
    error('ERROR (problem with the cover image)');
end

nzAC = numel(DCT) - numel(DCT(1:8:end, 1:8:end)); %计算AC系数个数
messageLen = length(message);

changeable = true(size(DCT)); %生成一个布尔矩阵
changeable(1:8:end, 1:8:end) = false; %DC系数的位置置为false
posAC = find(changeable); %找出布尔矩阵中为true的位置,即AC系数的位置

idMsg = 1;
idD = 1;

while idMsg <= messageLen
    while idD <= nzAC && DCT(posAC(idD)) == 0
        idD = idD + 1;
    end

    %信息过长
    if idD > nzAC
        error('ERROR (too long message)');
    end

    if message(idMsg) ~= mod(DCT(posAC(idD)), 2) %LSB与隐藏信息不同
        if DCT(posAC(idD)) > 0
            DCT(posAC(idD)) = DCT(posAC(idD)) - 1;
        end
    else %LSB与隐藏信息相同
        if DCT(posAC(idD)) < 0
            DCT(posAC(idD)) = DCT(posAC(idD)) + 1;
        end
    end
    if DCT(posAC(idD)) == 0
        idMsg = idMsg - 1;
    end
    idMsg = idMsg + 1;
    idD = idD + 1;
end

%%% save the resulting stego image
try
    jobj.coef_arrays{1} = DCT;
    jobj.optimize_coding = 1;
    jpeg_write(jobj, STEGO);
catch
    error('ERROR (problem with saving the stego image)');
end

%显示未嵌入信息的图像
subplot(2, 3, 1);
imshow(COVER);
title('未嵌入信息的图像');

%显示未嵌入信息的图像的DCT系数直方图
subplot(2, 3, [2, 3]);
histogram(PrimeDCT);
axis([-10, 10, 0, 2 * 1e4]);
title('嵌入前的图像DCT系数直方图');

%显示嵌入信息的图像
subplot(2, 3, 4);
imshow(STEGO);
title('嵌入信息的图像');

%显示嵌入信息的图像的DCT系数直方图
subplot(2, 3, [5, 6]);
histogram(DCT);
axis([-10, 10, 0, 2 * 1e4]);
title('嵌入后的图像DCT系数直方图');

stego.m

COVER = 'cover.jpg';
STEGO = 'stego.jpg';

messageLen = 30000;

message = randi([0, 1], 1, messageLen); %生成随机数,作为隐藏信息
save('message', 'message', '-mat'); %保存秘密信息

tic;
[nzAC] = F4_simulation(COVER, STEGO, message);
T = toc;

fprintf('-----------------------------------\n');
fprintf('F4 simulation finished\n');
fprintf('cover image: %s\n', COVER);
fprintf('stego image: %s\n', STEGO);
fprintf('number of nzACs in cover: %i\n', nzAC);
fprintf('elapsed time: %.4f seconds\n', T);
fprintf('-----------------------------------\n');

提取算法

F4_extract.m

function message = F4_extract(STEGO, messageLen)

try
    jobj = jpeg_read(STEGO); %读取stego图片
    DCT = jobj.coef_arrays{1}; %读取DCT系数
catch
    error('ERROR (problem with the cover image)');
end

nzAC = numel(DCT) - numel(DCT(1:8:end, 1:8:end)); %计算AC系数个数

changeable = true(size(DCT)); %生成一个布尔矩阵
changeable(1:8:end, 1:8:end) = false; %DC系数的位置置为false
posAC = find(changeable); %找出布尔矩阵中为true的位置,即AC系数的位置

idMsg = 1;
idD = 1;

message = linspace(0, 0, messageLen);

while idMsg <= messageLen
    while idD <= nzAC && DCT(posAC(idD)) == 0
        idD = idD + 1;
    end

    if idD > nzAC
        error('ERROR (wrong hiden message length)');
    end

    if DCT(posAC(idD)) > 0
        message(id) = mod(DCT(posAC(idD)), 2);
    else
        if mod(DCT(posAC(idD)), 2)
            message(id) = 0;
        else
            message(id) = 1;
        end
    end
    idD = idD + 1;
end

extract.m

STEGO = 'stego.jpg';

messageLen = 30000;

tic;
messageHiden = F4_extract(STEGO, messageLen);
T = toc;

save('messageHiden', 'messageHiden', '-mat'); %保存提取出来的秘密信息

fprintf('-----------------------------------\n');
fprintf('F4 extract finished\n');
fprintf('elapsed time: %.4f seconds\n', T);
fprintf('-----------------------------------\n');

实验结果

信息嵌入

       运行F4信息隐藏算法隐藏过程的实现代码stego.m。观察到嵌入完成,并且原始图像和载密相差甚微,DCT直方图差异不大。
F4信息隐藏算法_第2张图片

信息提取

       运行F4信息隐藏算法提取过程的实现代码extract.m。观察到提取完成。
F4信息隐藏算法_第3张图片

信息比对

       查看提取出来的秘密信息文件messageHiden,与原始秘密信息文件message比对,观察到提取出来的秘密信息是正确的。
信息比对

参考文献

       [1] 孔祥维等.多媒体信息安全实践教程.科学出版社

你可能感兴趣的:(图像信息隐藏,图像信息隐藏,f4,LSB,matlab,信息隐藏)