Add files via upload

This commit is contained in:
sanwu4617 2023-11-22 13:56:17 +08:00 committed by GitHub
commit 252b8d9386
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 448 additions and 0 deletions

30
SetBlackWhite.m Normal file
View File

@ -0,0 +1,30 @@
function [ x ] = SetBlackWhite( A )
%UNTITLED
%
[m,n]=size(A);
for i=1:m
for j=1:n
if(A(i,j)>=128)
delta=A(i,j)-255;
A(i,j)=255;
else
delta=A(i,j);
A(i,j)=0;
end;
if(j<n)
A(i,j+1)=A(i,j+1)+delta*7/16;
end;
if(j<n && i<m)
A(i+1,j+1)=A(i+1,j+1)+delta*1/16;
end;
if(i<m)
A(i+1,j)=A(i+1,j)+delta*5/16;
end;
if(i<m && j>1)
A(i+1,j-1)=A(i+1,j-1)+delta*3/16;
end;
end;
end;
x=A;
end

61
black_white.m Normal file
View File

@ -0,0 +1,61 @@
A=imread('test1.png');
A=rgb2gray(A);
[m,n]=size(A);
two1=uint8([255,255;0,0]);
two2=uint8([255,0;255,0]);
two3=uint8([255,0;0,255]);
two4=uint8([0,255;255,0]);
two5=uint8([0,255;0,255]);
two6=uint8([0,0;255,255]);
ans1=int8(floor(unifrnd(1,7,m,n)));
image1=uint8(zeros(2*m,2*n));
image2=uint8(zeros(2*m,2*n));
for i=1:m
for j=1:n
if(A(i,j)>=128) %±íʾ°×É«
switch ans1(i,j)
case 1
image1(2*i-1:2*i,2*j-1:2*j)=two1;
image2(2*i-1:2*i,2*j-1:2*j)=two1;
case 2
image1(2*i-1:2*i,2*j-1:2*j)=two2;
image2(2*i-1:2*i,2*j-1:2*j)=two2;
case 3
image1(2*i-1:2*i,2*j-1:2*j)=two3;
image2(2*i-1:2*i,2*j-1:2*j)=two3;
case 4
image1(2*i-1:2*i,2*j-1:2*j)=two4;
image2(2*i-1:2*i,2*j-1:2*j)=two4;
case 5
image1(2*i-1:2*i,2*j-1:2*j)=two5;
image2(2*i-1:2*i,2*j-1:2*j)=two5;
otherwise
image1(2*i-1:2*i,2*j-1:2*j)=two6;
image2(2*i-1:2*i,2*j-1:2*j)=two6;
end;
else
switch ans1(i,j)
case 1
image1(2*i-1:2*i,2*j-1:2*j)=two1;
image2(2*i-1:2*i,2*j-1:2*j)=two6;
case 2
image1(2*i-1:2*i,2*j-1:2*j)=two2;
image2(2*i-1:2*i,2*j-1:2*j)=two5;
case 3
image1(2*i-1:2*i,2*j-1:2*j)=two3;
image2(2*i-1:2*i,2*j-1:2*j)=two4;
case 4
image1(2*i-1:2*i,2*j-1:2*j)=two4;
image2(2*i-1:2*i,2*j-1:2*j)=two3;
case 5
image1(2*i-1:2*i,2*j-1:2*j)=two5;
image2(2*i-1:2*i,2*j-1:2*j)=two2;
otherwise
image1(2*i-1:2*i,2*j-1:2*j)=two6;
image2(2*i-1:2*i,2*j-1:2*j)=two1;
end;
end;
end;
end;
imwrite(image1,'bw_image1.png');
imwrite(image2,'bw_image2.png');

116
color.m Normal file
View File

@ -0,0 +1,116 @@
A=imread('test3.png');
A=uint16(A);
[m,n,p]=size(A);
two1=uint8([255,255;0,0]);
two2=uint8([255,0;255,0]);
two3=uint8([255,0;0,255]);
two4=uint8([0,255;255,0]);
two5=uint8([0,255;0,255]);
two6=uint8([0,0;255,255]);
ans1=int8(floor(unifrnd(1,7,m,n,3)));
image1=uint8(zeros(2*m,2*n,3));
image2=uint8(zeros(2*m,2*n,3));
for i=1:m
for j=1:n
for k=1:3
if(A(i,j,k)>=128)
delta=A(i,j,k)-255;
A(i,j,k)=255;
else
delta=A(i,j,k);
A(i,j,k)=0;
end;
if(j<n)
A(i,j+1,k)=A(i,j+1,k)+delta*7/16;
end;
if(j<n && i<m)
A(i+1,j+1,k)=A(i+1,j+1,k)+delta*1/16;
end;
if(i<m)
A(i+1,j,k)=A(i+1,j,k)+delta*5/16;
end;
if(i<m && j>1)
A(i+1,j-1,k)=A(i+1,j-1,k)+delta*3/16;
end;
end;
end;
end;
imwrite(uint8(A),'test3_1.png');
for i=1:m
for j=1:n
for k=1:3
if(A(i,j,k)<128) %
switch ans1(i,j,k)
case 1
image1(2*i-1:2*i,2*j-1:2*j,k)=two1;
image2(2*i-1:2*i,2*j-1:2*j,k)=two1;
case 2
image1(2*i-1:2*i,2*j-1:2*j,k)=two2;
image2(2*i-1:2*i,2*j-1:2*j,k)=two2;
case 3
image1(2*i-1:2*i,2*j-1:2*j,k)=two3;
image2(2*i-1:2*i,2*j-1:2*j,k)=two3;
case 4
image1(2*i-1:2*i,2*j-1:2*j,k)=two4;
image2(2*i-1:2*i,2*j-1:2*j,k)=two4;
case 5
image1(2*i-1:2*i,2*j-1:2*j,k)=two5;
image2(2*i-1:2*i,2*j-1:2*j,k)=two5;
otherwise
image1(2*i-1:2*i,2*j-1:2*j,k)=two6;
image2(2*i-1:2*i,2*j-1:2*j,k)=two6;
end;
else
switch ans1(i,j,k)
case 1
image1(2*i-1:2*i,2*j-1:2*j,k)=two1;
image2(2*i-1:2*i,2*j-1:2*j,k)=two6;
case 2
image1(2*i-1:2*i,2*j-1:2*j,k)=two2;
image2(2*i-1:2*i,2*j-1:2*j,k)=two5;
case 3
image1(2*i-1:2*i,2*j-1:2*j,k)=two3;
image2(2*i-1:2*i,2*j-1:2*j,k)=two4;
case 4
image1(2*i-1:2*i,2*j-1:2*j,k)=two4;
image2(2*i-1:2*i,2*j-1:2*j,k)=two3;
case 5
image1(2*i-1:2*i,2*j-1:2*j,k)=two5;
image2(2*i-1:2*i,2*j-1:2*j,k)=two2;
otherwise
image1(2*i-1:2*i,2*j-1:2*j,k)=two6;
image2(2*i-1:2*i,2*j-1:2*j,k)=two1;
end;
end;
end;
end;
end;
imwrite(image1,'color_image1.png');
imwrite(image2,'color_image2.png');
%
image1=uint16(image1);
image2=uint16(image2);
image_overlie=uint8(zeros(2*m,2*n,3));
image_compose=uint8(zeros(m,n,3));
for i=1:2*m
for j=1:2*n
for k=1:3
image_overlie(i,j,k)=image1(i,j,k)+image2(i,j,k);
end;
end;
end;
for i=1:m
for j=1:n
for k=1:3
a=uint16(image_overlie(2*i-1,2*j-1,k))+uint16(image_overlie(2*i-1,2*j,k))+ ...
uint16(image_overlie(2*i,2*j-1,k))+uint16(image_overlie(2*i,2*j,k));
if(a<512) %
image_compose(i,j,k)=0;
else
image_compose(i,j,k)=255;
end;
end;
end;
end;
imwrite(image_overlie,'image_overlie.png');
imwrite(image_compose,'image_compose.png');

87
gray.m Normal file
View File

@ -0,0 +1,87 @@
A=imread('test2.png');
A1=rgb2gray(A);
A=uint16(A1);
[m,n]=size(A);
two1=uint8([255,255;0,0]);
two2=uint8([255,0;255,0]);
two3=uint8([255,0;0,255]);
two4=uint8([0,255;255,0]);
two5=uint8([0,255;0,255]);
two6=uint8([0,0;255,255]);
ans1=int8(floor(unifrnd(1,7,m,n)));
image1=uint8(zeros(2*m,2*n));
image2=uint8(zeros(2*m,2*n));
for i=1:m
for j=1:n
if(A(i,j)>=128)
delta=A(i,j)-255;
A(i,j)=255;
else
delta=A(i,j);
A(i,j)=0;
end;
if(j<n)
A(i,j+1)=A(i,j+1)+delta*7/16;
end;
if(j<n && i<m)
A(i+1,j+1)=A(i+1,j+1)+delta*1/16;
end;
if(i<m)
A(i+1,j)=A(i+1,j)+delta*5/16;
end;
if(i<m && j>1)
A(i+1,j-1)=A(i+1,j-1)+delta*3/16;
end;
end;
end;
imwrite(uint8(A),'test2_blackwhite.png');
for i=1:m
for j=1:n
if(A(i,j)>=128) %±íʾ°×É«
switch ans1(i,j)
case 1
image1(2*i-1:2*i,2*j-1:2*j)=two1;
image2(2*i-1:2*i,2*j-1:2*j)=two1;
case 2
image1(2*i-1:2*i,2*j-1:2*j)=two2;
image2(2*i-1:2*i,2*j-1:2*j)=two2;
case 3
image1(2*i-1:2*i,2*j-1:2*j)=two3;
image2(2*i-1:2*i,2*j-1:2*j)=two3;
case 4
image1(2*i-1:2*i,2*j-1:2*j)=two4;
image2(2*i-1:2*i,2*j-1:2*j)=two4;
case 5
image1(2*i-1:2*i,2*j-1:2*j)=two5;
image2(2*i-1:2*i,2*j-1:2*j)=two5;
otherwise
image1(2*i-1:2*i,2*j-1:2*j)=two6;
image2(2*i-1:2*i,2*j-1:2*j)=two6;
end;
else
switch ans1(i,j)
case 1
image1(2*i-1:2*i,2*j-1:2*j)=two1;
image2(2*i-1:2*i,2*j-1:2*j)=two6;
case 2
image1(2*i-1:2*i,2*j-1:2*j)=two2;
image2(2*i-1:2*i,2*j-1:2*j)=two5;
case 3
image1(2*i-1:2*i,2*j-1:2*j)=two3;
image2(2*i-1:2*i,2*j-1:2*j)=two4;
case 4
image1(2*i-1:2*i,2*j-1:2*j)=two4;
image2(2*i-1:2*i,2*j-1:2*j)=two3;
case 5
image1(2*i-1:2*i,2*j-1:2*j)=two5;
image2(2*i-1:2*i,2*j-1:2*j)=two2;
otherwise
image1(2*i-1:2*i,2*j-1:2*j)=two6;
image2(2*i-1:2*i,2*j-1:2*j)=two1;
end;
end;
end;
end;
imwrite(image1,'gray_image1.png');
imwrite(image2,'gray_image2.png');

154
image_covering_gray.m Normal file
View File

@ -0,0 +1,154 @@
key1_image=rgb2gray(imread('a.png'));
key2_image=rgb2gray(imread('b.png'));
cipher_image=rgb2gray(imread('test1.png'));
[m,n]=size(key1_image);
two1=uint8([255,255;0,0]);
two2=uint8([255,0;255,0]);
two3=uint8([255,0;0,255]);
two4=uint8([0,255;255,0]);
two5=uint8([0,255;0,255]);
two6=uint8([0,0;255,255]);
three1=uint8([255,0;0,0]);
three2=uint8([0,255;0,0]);
three3=uint8([0,0;255,0]);
three4=uint8([0,0;0,255]);
ans1=int8(floor(unifrnd(1,5,m,n)));
key1=uint8(zeros(2*m,2*n));
key2=uint8(zeros(2*m,2*n));
key1_image=SetBlackWhite(key1_image);
key2_image=SetBlackWhite(key2_image);
cipher_image=SetBlackWhite(cipher_image);
%imwrite(key1_image,'key1_image1.png');
%imwrite(key2_image,'key2_image1.png');
%imwrite(cipher_image,'cipher_image1.png');
temps=uint8(zeros(m,n));
for i=1:m
for j=1:n
temp=key1_image(i,j)/255*4+key2_image(i,j)/255*2+cipher_image(i,j)/255;
temps(i,j)=temp;
switch temp
case 0
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=three1;
key2(2*i-1:2*i,2*j-1:2*j)=three3;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=three2;
key2(2*i-1:2*i,2*j-1:2*j)=three4;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=three3;
key2(2*i-1:2*i,2*j-1:2*j)=three1;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=three4;
key2(2*i-1:2*i,2*j-1:2*j)=three2;
end;
case 1
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=three1;
key2(2*i-1:2*i,2*j-1:2*j)=three1;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=three2;
key2(2*i-1:2*i,2*j-1:2*j)=three2;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=three3;
key2(2*i-1:2*i,2*j-1:2*j)=three3;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=three4;
key2(2*i-1:2*i,2*j-1:2*j)=three4;
end;
case 2
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=three1;
key2(2*i-1:2*i,2*j-1:2*j)=two4;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=three2;
key2(2*i-1:2*i,2*j-1:2*j)=two2;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=three3;
key2(2*i-1:2*i,2*j-1:2*j)=two3;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=three4;
key2(2*i-1:2*i,2*j-1:2*j)=two1;
end;
case 3
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=three1;
key2(2*i-1:2*i,2*j-1:2*j)=two1;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=three2;
key2(2*i-1:2*i,2*j-1:2*j)=two5;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=three3;
key2(2*i-1:2*i,2*j-1:2*j)=two6;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=three4;
key2(2*i-1:2*i,2*j-1:2*j)=two3;
end;
case 4
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=two4;
key2(2*i-1:2*i,2*j-1:2*j)=three1;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=two6;
key2(2*i-1:2*i,2*j-1:2*j)=three2;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=two5;
key2(2*i-1:2*i,2*j-1:2*j)=three3;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=two2;
key2(2*i-1:2*i,2*j-1:2*j)=three4;
end;
case 5
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=two1;
key2(2*i-1:2*i,2*j-1:2*j)=three1;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=two4;
key2(2*i-1:2*i,2*j-1:2*j)=three2;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=two6;
key2(2*i-1:2*i,2*j-1:2*j)=three3;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=two3;
key2(2*i-1:2*i,2*j-1:2*j)=three4;
end;
case 6
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=two1;
key2(2*i-1:2*i,2*j-1:2*j)=two6;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=two2;
key2(2*i-1:2*i,2*j-1:2*j)=two5;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=two3;
key2(2*i-1:2*i,2*j-1:2*j)=two4;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=two4;
key2(2*i-1:2*i,2*j-1:2*j)=two3;
end;
case 7
switch ans1(i,j)
case 1
key1(2*i-1:2*i,2*j-1:2*j)=two1;
key2(2*i-1:2*i,2*j-1:2*j)=two2;
case 2
key1(2*i-1:2*i,2*j-1:2*j)=two2;
key2(2*i-1:2*i,2*j-1:2*j)=two3;
case 3
key1(2*i-1:2*i,2*j-1:2*j)=two5;
key2(2*i-1:2*i,2*j-1:2*j)=two4;
case 4
key1(2*i-1:2*i,2*j-1:2*j)=two6;
key2(2*i-1:2*i,2*j-1:2*j)=two5;
end;
end;
end;
end;
imwrite(key1,'key1.png');
imwrite(key2,'key2.png');