MATLAB 实现 stegsolve

Author Avatar
Tr0y 6月 14, 2017 16:25:18 本文共 377 字
  • 文为知己者书
  • 在其它设备中阅读本文章

实现或者通读代码能更深入了解知识以及工具的使用, 也能方便进行扩展.

代码

clc;clear;
pic='lsb.png';
[I, ~, alpha]=imread(pic);
[X,Y,~]=size(I);
if isempty(alpha)
    alpha=ones([X,Y])*255;
end
speed=0.5;
color={'red','green','blue', 'alpha'};
imshow(I); % 原图
pause(1);

%r, g, b plane i
for plane=1:3 % r, g, b
    for bit=1:8
        pause(speed);
        bits=bitget(I, bit); % plane i
        imshow(logical(bits(:, :, plane))); 
        title(strcat(color(plane), ' plane-', num2str(bit)));
    end
end

%alpha plane i
plane=4;
for bit=1:8
    pause(speed);
    bits=bitget(alpha, bit); % plane i
    imshow(logical(bits)); 
    title(strcat(color(plane), ' plane-', num2str(bit)));

end

%random color map
for plane=1:3
    I0=I;
    y0=bitget(I0, 1);


    for bit=1:3
        bits=y0(:, :, bit);
        bits(find(bits == 0))=randi([1, 255]);
        bits(find(bits == 1))=randi([1, 255]);
        I0(:, :, bit)=bits;
    end
    imshow(I0);  
    title(strcat( 'random color map-', num2str(plane)));
    pause(speed)
end

%Full 
R=I;R(:,:,[2 3])=0;
G=I;G(:,:,[1 3])=0;
B=I;B(:,:,[1 2])=0;
A=alpha;A(:,:,[2 3])=0;
imshow(R);title('Full Red');pause(speed)
imshow(G);title('Full Green');pause(speed)
imshow(B);title('Full Blue');pause(speed)
imshow(A);title('Full Alpha');pause(speed)

%colour inversion (xor)
imshow(255 - imread(pic));
title('colour inversion');pause(speed);

%Gray bits
I0=I;

for x=1:X
   for y =1:Y
      if isequal(I0(x,y,1),I0(x,y,2),I0(x,y,3))==1 %RGB3 个值相等
          I0(x,y,1)=255;
          I0(x,y,2)=255;
          I0(x,y,3)=255;
      else
          I0(x,y,1)=0;
          I0(x,y,2)=0;
          I0(x,y,3)=0;
      end
   end
end
imshow(I0)
title('Gray bits');

上述代码实现了 stegsolve 的所有 LSB 像素隐写功能.

详细代码解释

LSB 像素隐写

End

What do you think?

本文标题: MATLAB 实现 stegsolve
原始链接: http://www.tr0y.wang/2017/06/14/MATLABstegsolve/
发布时间: 2017.06.14-16:25
最后更新: 2018.11.03-20:49
版权声明: 本站文章均采用CC BY-NC-SA 4.0协议进行许可。转载请注明出处!