⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doublerandomphaseencryptionofbiologytrait.m

📁 这个程序用于图像的加密和隐藏
💻 M
字号:
clear all
I=imread('test.tif');
A=double(I);%f
figure;imagesc(A);
colormap(gray);
title('the fist orignal image');
J=imread('saturn.tif');
J1=imresize(J,[128,128]);
B=double(J1);%p
figure;imagesc(B);
colormap(gray);
title('the second image')
%produce the encrypted image]
B1=exp(i*2*pi*B);
C=rand(128,128);%the first mask
C1=exp(i*2*pi*C);
F=B1.*C1;
F1=A.*F;
F11=fft2(F1);
D=rand(128,128);%the second mask
D1=exp(i*2*pi*D);
F111=F11.*D1;
F1111=ifft2(F111);
K=abs(F1111);
figure;imagesc(K);
colormap(gray);
title('the encrypted image');
%decrypted the image
E=fft2(F1111);
E1=E.*exp(-i*2*pi*D);
E11=ifft2(E1);
E111=E11.*exp(-i*2*pi*C);
T=abs(E11);
figure;imagesc(T);
colormap(gray);
title('the first decrypted imge');
T1=angle(E111)/(2*pi);
figure,imagesc(T1);
colormap(gray);
title('the second decrypted image')
%the second produre
%only using the amplitude part to decryption
%produce the original image
I=imread('blood1.tif');
imagesc(I);
colormap(gray);
title('the original image');
A=double(I);
%produce the encrypted image
R1=rand(265,272);
R11=double(R1);
r1=exp(i*2*pi*R11);
r11=A.*r1;
r111=fft2(r11);
R2=rand(265,272);
R22=double(R2);
r2=exp(i*2*pi*R22);
r22=r111.*r2;
r222=ifft2(r22);
R=abs(r222);
figure;imagesc(R);
colormap(gray);
title('the encrypted image');
%extract the amplitude part
a=A^(1/2);
%produce the decrypted image
A1=fft2(a);
A11=A1.*exp(-i*2*pi*R22);
B1=ifft2(A11);
B11=B1.*exp(-i*2*pi*R11);
B=abs(B11);
figure;imagesc(B);
colormap(gray);
title('the decrypted image');
%The third procedure
%the original image
I=imread('test.tif');
A=double(I);
A1=abs(A);
imagesc(A1);
colormap(gray);
title('the original image');
%the encrypted image
key1=rand(128,128);
r1=exp(i*2*pi*key1);
r11=A.*r1;
B=fft2(r11);
key2=rand(128,128);
r2=exp(i*2*pi*key2);
r22=B.*r2;
e=ifft2(r22);
E=abs(e);
figure;imagesc(E);
colormap(gray);
title('the encrypted image');
F=fft2(e);
F1=abs(F);
P=rand(128,128);
P1=2*pi*P;
j=0;
while(j<1)
    P11=exp(i*P1);
    C=A1.*P11;
    C1=fft2(C);
    N1=angle(C1);
    D=F1.*exp(i*N1);
    D1=ifft2(D);
    P1=angle(D1);
    j=j+1;
end
K=A1.*exp(i*P1);
K1=fft2(K);
K2=K1./F;
%the decrypted image
G=fft2(e);
G1=G.*K2;
G11=ifft2(G1);
G2=G11.*exp(-i*P1);
G22=abs(G2);
figure;imagesc(G22);
colormap(gray);
title('the decrypted image');
%The forth 
clear all;
close all;
clc;

%读取原图像,其大小为[128,128],并显示
I=imread('test.tif');
figure;imshow(I);
title('Originadl Image');
A=double(I);

%从key1.dat中获得密钥mask1
fid=fopen('key1.dat','rb');
key1=fread(fid,[128,128],'double');
fclose(fid);
r1=exp(i*2*pi*key1);

%从key2.dat中获得密钥mask1
fid=fopen('key2.dat','rb');
key2=fread(fid,[128,128],'double');
fclose(fid);
r2=exp(i*2*pi*key2);

%产生加密图像B
B=A.*r1;%2、通过mask1
B1=fft2(B);%3、通过透镜1
B2=B1.*r2;%4、通过mask2
B3=ifft2(B2);%5、通过透镜2
A_show=mat2gray(abs(B3));%产生加密图像A
figure;imshow(A_show);
%figure;imshow(real(B));
title('Encrypted Image');

%把加密后的图像保存
fid=fopen('encrption.dat','wb');
fwrite(fid,B3,'double');
fclose(fid);

%----------------------------------------------------------------

%从key1.dat中获得密钥mask1
fid=fopen('key1.dat','rb');
key1=fread(fid,[128,128],'double');
fclose(fid);
key1=exp(-i*2*pi*key1);

%从key2.dat中获得密钥mask1
fid=fopen('key2.dat','rb');
key2=fread(fid,[128,128],'double');
fclose(fid);
key2=exp(-i*2*pi*key2);

%产生解密图像AA
AA=fft2(B3);%2、通过透镜1
AA=AA.*key2;%3、通过mask2的共轭
AA=ifft2(AA);%4、通过透镜2
AA=AA.*key1;%5、通过mask1的共轭
AA_show=mat2gray(real(AA));
%AA_show=real(AA);
figure;imshow(AA_show);
title('Deciphered Image');



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -