K=imread('SHNU.bmp');
height=info.Height;width=info.Width;
A=zeros(height,width);
B=zeros(height,width);
C=zeros(height,width);
% 随机生成A,B,C矩阵
for i=1: height
for j=1: width
random=rand()*2;
if(random>1)
A(i,j)=1;B(i,j)=1;C(i,j)=1;
else
A(i,j)=0;B(i,j)=0;C(i,j)=0;
end
end
end
%%%%%生成子秘钥A,B,C图片
for i=1: height
for j=1: width
if(K(i,j)==0)
random=rand()*4;
if(random<1)
A(i,j)=0;A(i,j+1)=0;A(i+1,j)=1;A(i+1,j+1)=1;
B(i,j)=0;B(i+1,j)=0;B(i,j+1)=1;B(i+1,j+1)=1;
C(i,j)=0;C(i+1,j+1)=0;C(i,j+1)=1;C(i+1,j)=1;
else if(random<2)
A(i,j)=0;A(i,j+1)=0;A(i+1,j)=1;A(i+1,j+1)=1;
C(i,j+1)=0;C(i+1,j)=0;C(i,j)=1;C(i+1,j+1)=1;
B(i,j+1)=0;B(i+1,j+1)=0;B(i,j)=1;B(i+1,j)=1;
else if(random<3)
B(i,j)=0;B(i+1,j)=0;B(i,j+1)=1;B(i+1,j+1)=1;
A(i+1,j)=0;A(i+1,j+1)=0;A(i,j)=1;A(i,j+1)=1;
C(i,j+1)=0;C(i+1,j)=0;C(i,j)=1;C(i+1,j+1)=1;
else if(random<4)
B(i,j+1)=0;B(i+1,j+1)=0;B(i,j)=1;B(i+1,j)=1;
C(i,j)=0;C(i+1,j+1)=0;C(i,j+1)=1;C(i+1,j)=1;
A(i+1,j)=0;A(i+1,j+1)=0;A(i,j)=1;A(i,j+1)=1;
end
end
end
end
end
end
end
imwrite(A,'a.bmp','bmp');
imwrite(B,'b.bmp','bmp');
imwrite(C,'c.bmp','bmp');
figure
subplot(2,2,1),imshow(K);
subplot(2,2,2),imshow(A);
subplot(2,2,3),imshow(B);
subplot(2,2,4),imshow(C);
axes_handle = get(gcf, 'children');
axes(axes_handle(4)); title('original image');
axes(axes_handle(3)); title('image a');
axes(axes_handle(2)); title('image b');
axes(axes_handle(1)); title('image c');
%%%%隐藏信息的恢复
A1=imread('a.bmp');
B1=imread('b.bmp');
C1=imread('c.bmp');
random=rand()*3;
if(random<1)
K=A1;K12=A1;K13=A1;K23=A1;
else if(random<2)
K=B1;K12=B1;K13=B1;K23=B1;
else
K=C1;K12=C1;K13=C1;K23=C1;
end
end
for i=1: height-1
for j=1: width-1
if((xor(xor(A1(i,j),B1(i,j)),C1(i,j))==0)&&(xor(xor(A1(i,j+1),B1(i,j+1)),C1(i,j+1))==0)&&(xor(xor(A1(i+1,j),B1(i+1,j)),C1(i+1,j))==0)&&(xor(xor(A1(i+1,j+1),B1(i+1,j+1)),C1(i+1,j+1))==0))
K(i,j)=0;K(i,j+1)=0;K(i+1,j)=0;K(i+1,j+1)=0;
end
end
end
for i=1: height-1,
for j=1: width-1,
if((A1(i,j)||B1(i,j))==0&&(A1(i,j+1)||B1(i,j+1))==0&&(A1(i+1,j)||B1(i+1,j))==0&&(A1(i+1,j+1)||B1(i+1,j+1))==0)
K12(i,j)=0;K12(i,j+1)=0;K12(i+1,j)=0;K12(i+1,j+1)=0;
end
end
end
for i=1: height-1,
for j=1: width-1,
if((A1(i,j)||C1(i,j))==0&&(A1(i,j+1)||C1(i,j+1))==0&&(A1(i+1,j)||C1(i+1,j))==0&&(A1(i+1,j+1)||C1(i+1,j+1))==0)
K13(i,j)=0;K13(i,j+1)=0;K13(i+1,j)=0;K13(i+1,j+1)=0;
end
end
end
for i=1: height-1,
for j=1: width-1,
if((C1(i,j)||B1(i,j))==0&&(C1(i,j+1)||B1(i,j+1))==0&&(C1(i+1,j)||B1(i+1,j))==0&&(C1(i+1,j+1)||B1(i+1,j+1))==0)
K23(i,j)=0;K23(i,j+1)=0;K23(i+1,j)=0;K23(i+1,j+1)=0;
end
end
end
imwrite(K,'K.bmp','bmp')
imwrite(K12,'image_a+b.bmp','bmp')
imwrite(K13,'image_a+c.bmp','bmp')
imwrite(K23,'image_b+c.bmp','bmp')
figure
imshow(K);
title('recovery image');
figure
subplot(2,2,1),imshow(K12);
subplot(2,2,2),imshow(K13);
subplot(2,2,3),imshow(K23);
axes_handle = get(gcf, 'children');
axes(axes_handle(3)); title('image a+b');
axes(axes_handle(2)); title('image a+c');
axes(axes_handle(1)); title('image b+c');
版权声明:本文为博主原创文章,未经博主允许不得转载。