MATLAB 实现 stegsolve

本文最后更新于:4 年前

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

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 像素隐写

来呀快活呀


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!