【问题标题】:Matlab computing wrong valuesMatlab计算错误值
【发布时间】:2020-11-12 13:53:15
【问题描述】:

我正在使用MATLAB 2013a来实现本文的算法An improved method for high hiding capacity based on LSB and PVD

论文中的图 3.1 描述了嵌入过程,当到达右分支的第 5 步时,MATLAB 计算出变量 v1v2 的错误值。这是我的代码:

counter =1;
for i=1:size(stego,1)
    for j=1:3:size(stego,2)
        %% Step 1: Let the three pixels of a block be Pi, Pi+1, and Pi+2.
        p0 = stego(i,j);
        p1 = stego(i,j+1);
        p2 = stego(i,j+2);
        %% Step 2: Suppose Pi <= Pi+1 and Pi <= Pi+2.
        if (p0 <= p1 && p0 <=p2)
          % some code is here.....
        else
          % Otherwise, the reference pixel is Pi+1, and apply the steps 8 to 12
            % to produce the stego-pixels.
            bits = sm(1, counter:counter+k-1); %sm is a binary string 0011101101011.....
            counter = counter+k;
            g1 = dec2bin(p1,8);
            k_old = bin2dec(g1(1,end-k+1:end));
            g1(1,end-k+1:end) = bits;
            k_new = bin2dec(bits);
            g1 = bin2dec(g1);

        % Compute the difference value kdif = kold ?knew.
        k_diff = k_old - k_new;
        
        % Now, compute P'i+1 using Eq. (3.22).
        if (k_diff > 2^(k-1) && (g1+2^k>=0 && g1+2^k<=255))
            p_1 = g1 + 2^k;
        elseif (k_diff < -2^(k-1) && (g1 - 2^k >=0 && g1 - 2^k <= 255))
            p_1 = g1 - 2^k;
        else
            p_1 = g1;
        end

        v11 = abs(p0 - p_1); %ERROR HAPPENS HERE
        v22 = abs(p2 - p_1); %ERROR HAPPENS HERE

        % REST OF THE CODE ....

(我已经删除了左分支的代码,因为它没有问题)

在调试我的代码时,matlab 正确显示了 p0 等于 64 和 p_1 等于 66 的值,所以等式 v11 = abs(p0 - p_1); 必须产生 2。但它给出 v11 = 0

Here is a screenshot of the values of the variables p0, p_1, and the result of v11 after executing the line while debugging.

那么,这是 Matlab 的错误吗?还是我的代码有问题?

【问题讨论】:

    标签: matlab security debugging image-processing steganography


    【解决方案1】:

    在您的调试中,请注意p0 的类型为uint8,值为64,即无符号8 位整数,而p_1double。从uint8 中减去双精度时,结果将是uint8,它不能表示负值。 Matlab 无符号整数饱和,因此结果为零。

    我建议将p0 的类型更改为有符号整数类型(也许int8 就足够了)。

    【讨论】:

    • 或者更好,写abs(double(p0) - p_1)
    • 是的,这取决于上下文。我认为 p_1 最初应该创建为整数,因为代码似乎与图像有关。
    猜你喜欢
    • 2012-12-26
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 2015-07-14
    • 2018-05-11
    • 1970-01-01
    • 2012-07-09
    • 2012-05-24
    相关资源
    最近更新 更多