Chi-square distribution of digital image steganography

1. Experimental purpose

1. Implement the chi-square analysis algorithm;

2. Chi-square analysis can be used to distinguish the cryptic image steganographed by LSB from the original carrier image that has not been modified by the steganography algorithm.

2. Problem description

1. Input form and input value range;

84 standard images in bmp format;

2. Output form;

task1: Chi-square analysis comparison chart and dividing line between the secret image and the original image;

task2: Use the segmentation value T in task1 to test the image type and obtain the prediction accuracy;

3. The functions that the program can achieve.

The classified image and the original image can be distinguished through the chi-square distribution test or eigenvalue test.

task1: 84 secret-containing images were obtained by embedding secret information in 84 standard library images. Two different chi-square analyzes were performed on a total of 168 images to obtain the chi-square value comparison chart and segmentation value under two different chi-square analysis methods. T;

Task2: Using 84 standard library images, the first 42 are embedded with secret information to form a secret image, and the last 42 are not embedded with secret information as the original image. Test the segmentation value T generated by task1 to distinguish the image type (original image or secret image) image) prediction accuracy.

3. Experimental principles

Simple LSB steganography algorithm pixel value modification analysis:

If the pixel value 2i is changed to 2i+1 or 2i+1 is changed to 2i, the embedded data d=0/1, the probability is 50%.

Let the number of pixels with gray value j be hj

Steganographic image compared to original image:

The values ​​of h2i and h2i+1 of the steganographic image will be closer (histograms appear in pairs). Figure 1 is the histogram of the original image, and Figure 2 is the histogram of the steganographic image.

Figure 1

Figure 2 

Find the smallest image that satisfies the statistics, and you can know whether the image is a steganographic image or an original image by judging the size relationship between the and .

4. Experimental design

The main functions task1.m and task2.m call the function StgPrb.m and the function Diff.m

Task1 uses 84 standard images as input and embeds secret information to obtain 84 secret images. That is, a total of 168 images are used for chi-square analysis to obtain the predicted segmentation value T and the chi-square value comparison chart.

The comparison of chi-square values ​​between the original image and the classified image in Chi-square analysis method 1 is shown in Figure 3;

image 3

 Logarithmically process the results of Chi-square analysis method 1 to make the results more obvious and reduce the difference in Chi-square values, as shown in Figure 4;

 

Figure 4 

The comparison chart of the chi-square value of the original image and the classified image in chi-square analysis method 2 is shown in Figure 5;

Figure 5

task2 uses 84 standard images as input, of which the first 42 images embed secret information so that their image embedding rate is 1, and the last 42 images do not embed any information. Then the card of the image is obtained by calling the function StgPrb.m and the function Diff.m square value, compare it with the segmentation value T, and predict the specific type of the image. By comparing the predicted type with the actual type, the prediction accuracy can be obtained.

The prediction accuracy using function StgPrb.m is 100%, and the prediction accuracy using function Diff.m is 98.81%.

Figure 6 below shows the actual type and predicted type of the image in detection method 1, where 1 represents the encrypted image and 0 represents the original image.

 Figure 6

Figure 7 below shows the actual type and predicted type of the image in detection method 2, where 1 represents the encrypted image and 0 represents the original image.

Figure 7

 5. Summary

After designing the Diff.m function, it was found that the chi-square values ​​of different images were very different. The log function was used to reduce the order of magnitude of the chi-square values ​​of different images, making the chi-square value results of different types of images more obvious.

I found a better chi-square analysis method on the Internet. It uses the chi2cdf function to cleverly make the scattered values ​​​​more regular. In the end, the chi-square value of most secret images reaches 1, and the chi-square value of the original image is 0. When the test uses 0.5 as the segmentation value to determine the image type, the prediction accuracy is as high as 100%.


6.Appendix code

task1.m

%% 清空环境
clc
clear
close all

%% 数据测试(84个训练图像)
cover=cell(84,1);
stego=cell(84,1);
sizes=zeros(84,2);
p1=zeros(84,2);
p2=zeros(84,2);
for k=1:84
    secret=rand(512)<0.5;
    %% 读取图像
    text=['original/',num2str(k),'.bmp'];
    cover{k}=imread(text);
    [sizes(k,1),sizes(k,2)]=size(cover{k});
   
    %% 求卡方值
    p1(k,1)=StgPrb(cover{k});
    %% 求特征值
    p2(k,1)=Diff(cover{k});
    
    %% 嵌入信息
    for i=1:sizes(k,1)
        for j=1:sizes(k,2)
            stego{k}(i,j)=bitset(cover{k}(i,j),1,secret(i,j));
        end
    end
    
    %% 求卡方值
    p1(k,2)=StgPrb(stego{k});
    %% 求特征值
    p2(k,2)=Diff(stego{k});
end

T=max(p2(:,2));

figure();
plot([1:84],p2(:,1),'r+',[1:84],p2(:,2),'b+',[1:84],ones(84,1).*T,'g-');
legend('原始图像','嵌入率为1的载密图像','分割线T');
xlabel('图像编号');
ylabel('特征值');

figure();
p2=log(p2);
T=log(T);
plot([1:84],p2(:,1),'r+',[1:84],p2(:,2),'b+',[1:84],ones(84,1).*T,'g-');
legend('原始图像','嵌入率为1的载密图像','分割线T');
xlabel('图像编号');
ylabel('log(特征值)');

figure();
plot([1:84],p1(:,1),'r+',[1:84],p1(:,2),'b+');
legend('原始图像','嵌入率为1的载密图像');
xlabel('图像编号');
ylabel('卡方值');

save T.mat T

task2.m

clc
clear
close all

load T.mat

%% 数据测试(84个测试图像)
cover=cell(84,1);
p1=zeros(84,1);
p2=zeros(84,1);
predict=zeros(84,2);
for k=1:42
    secret=rand(512)<0.5;
    %% 读取图像
    text=['original/',num2str(k),'.bmp'];
    cover{k}=imread(text);
    [sizes(k,1),sizes(k,2)]=size(cover{k});
    
    %% 嵌入信息
    for i=1:sizes(k,1)
        for j=1:sizes(k,2)
            cover{k}(i,j)=bitset(cover{k}(i,j),1,secret(i,j));
        end
    end
    
    %% 求卡方值
    p1(k)=StgPrb(cover{k});
    %% 求特征值
    p2(k)=Diff(cover{k});
    p2(k)=log(p2(k));
    
    if p1(k)>0.5
        predict(k,1)=1;
    else
        predict(k,1)=0;
    end
    
    if p2(k)>T
        predict(k,2)=0;
    else
        predict(k,2)=1;
    end
end

for k=43:84
    %% 读取图像
    text=['original/',num2str(k),'.bmp'];
    cover{k}=imread(text);
    [sizes(k,1),sizes(k,2)]=size(cover{k});
 
    %% 求卡方值
    p1(k)=StgPrb(cover{k});
    %% 求特征值
    p2(k)=Diff(cover{k});
    p2(k)=log(p2(k));
    
    if p1(k)>0.5
        predict(k,1)=1;
    else
        predict(k,1)=0;
    end
    
    if p2(k)>T
        predict(k,2)=0;
    else
        predict(k,2)=1;
    end
end

%% 求预测准确度
predict_rate1=0;
predict_rate2=0;
for k=1:42
    if predict(k,1)==1
        predict_rate1=predict_rate1+1;
    end
    if predict(k,2)==1
        predict_rate2=predict_rate2+1;
    end
end

for k=43:84
    if predict(k,1)==0
        predict_rate1=predict_rate1+1;
    end
    if predict(k,2)==0
        predict_rate2=predict_rate2+1;
    end
end
predict_rate1=predict_rate1/84
predict_rate2=predict_rate2/84
dx=[1:84];
real=[ones(1,42),zeros(1,42)];
figure();
plot(dx,real,'r*',dx,predict(:,1),'bo');
title("检验方法1");
legend('实际类型','预测类型');
figure();
plot(dx,real,'r*',dx,predict(:,2),'bo');
title("检验方法2");
legend('实际类型','预测类型');

StgPrb.m

function p=StgPrb(x)
n=sum(hist(x,[0:255]),2);
h2i=n([3:2:255]);
h2is=(h2i+n([4:2:256]))/2;
filter=(h2is~=0);
k=sum(filter);
idx=zeros(1,k);
for i=1:127
    if filter(i)==1
        idx(sum(filter(1:i)))=i;
    end
end
r=sum(((h2i(idx)-h2is(idx)).^2)./(h2is(idx)));
p=1-chi2cdf(r,k-1);

Diff.m

function p=Diff(x)
p=0;
[n,~]=imhist(x);
for i=0:127
    p=p+(n(2*i+1)-n(2*i+2))^2;
end

Guess you like

Origin blog.csdn.net/HUANGliang_/article/details/125995852