相干光衍射原理衍射积分代码( 三 )


四步相移全息术主函数:
%---注意:本文利用角谱传播,其中包括了傅里叶变换,注意采样条件----%%Notice:This promgram adopts the angular diffraction.%%It includes the Fourier Transform. Pay attention to%%---the sampling condition---%%% 单位定义 Define unit %%clear all;clc;cm=0.01;um=1e-6;mm=0.001;%% 载入图像 load the image %%load('eword.mat');B=eword;clear('eword');%% 将图片变为方阵 Change the object into a square matrix %%[m,n]=size(B);ms=max([m,n]);A=zeros(ms,ms);A(1+floor((ms-m)/2):m+floor((ms-m)/2),1+floor((ms-n)/2):n+floor((ms-n)/2))=B;times=10;[m,n]=size(A);multiples=2;M=2.*m.*multiples;N=2.*n.*multiples;%% 设定仿真参数 Parameter setting of simulation----------%%%z:传输距离Diffraction distance%%lambda:波长Wavelength%%k:波矢量Wave vector%%hx&hy:原始图大小Size of image%%%dhx&dhy:尺寸对像素微分Differential of size to pixel %%--------------------------------------------------------%z=100.*cm;%传输距离Diffraction distancelambda=0.63*um;%波长Wavelengthk=2*pi/lambda;%波矢量Wave vectorhx=5*cm;hy=5*cm;%原始图大小 Size of imagedhx=hx/N;dhy=hy/M;x=dhx.*(ones(N,1)*[-M/2:M/2-1]); y=(dhy.*(ones(N,1)*[-M/2:M/2-1]))';%% figure;imshow(abs(A).^2);%原始图[lm,ln]=size(A);%% 扩充图像 Padding the image %%f0=zeros(N,1)*[1:M];light0=f0;light=ones(lm,ln);f0(M/2-M/4/multiples+1:M/2+M/4/multiples,N/2-N/4/multiples+1:N/2+N/4/multiples)=A;%扩充图像%% 设定激光器发出光束 Setting of laser ------------------------------- %%% light0 定义了激光束的形状, 在此程序中, light0为256x256的方形,变量f0是%% 扩充后的物体图%% light0 decide the shape of laser. In this program, it's square with %% 256x256 pixel. The variable f0 is padding image of object% % ------------------------------------------------------------------% light0(M/2-M/4/multiples+1:M/2+M/4/multiples,N/2-N/4/multiples+1:N/2+N/4/multiples)=light;%设置激光器光束形状和大小(方形,256x256)light0=angulardiffraction(light0,hx,hy,10.*cm,lambda);%激光器发出光束传播至被拍照物体clear('light');f0=light0.*f0;%激光与目标作用[image] = angulardiffraction(f0,hx,hx,z,lambda);%被拍照物体衍射至全息干板figure('name','diffraction');imshow(mat2gray(abs(image).^2));%% 设定参考光 Setting of reference light------ %%% alpha :angle between x axis and light vector%% beta:angle between y axis and light vector%% alpha :x轴与光矢量之间的夹角%% beta:y轴与光矢量之间的夹角%% ----------------------------------------------%alpha=90/180*pi;beta=(90)/180*pi; pic=zeros(M,N);pic(M/2-M/4+1:M/2+M/4,M/2-M/4+1:M/2+M/4)=1;ur=exp(1j*k*(cos(alpha)*x+cos(beta)*y)).*pic;%refernce light,parallel light%% 四步相移 Four step phase shift----------------------%%%参考:四步相移; 功能:从 hologram0~3提取图像复振幅%%Method reference:This formula refers to four step %%phase shift method%%Function:Extract the origin image's complex%%amplitude from hologram0~3%%----------------------------------------------------%%reference light phase shift 四步相移 ur0=ur;ur1=ur.*exp(1j.*pi./2);ur2=ur.*exp(1j.*pi);ur3=ur.*exp(1j.*pi.*3./2);%inteference between object and reference,物光、参考光干涉 %hologram0=ur0+image;hologram1=ur1+image;hologram2=ur2+image;hologram3=ur3+image;hologram0=abs(hologram0).^2;hologram1=abs(hologram1).^2;hologram2=abs(hologram2).^2;hologram3=abs(hologram3).^2;hologram=((hologram0-hologram2)+1j.*(hologram3-hologram1))./4; %% 显示衍射结果 Show the results of diffraction %%phi=angle(hologram);figure('name','hologram');imshow(mat2gray(abs(hologram).^2));figure('name','phase map');imshow(mat2gray(phi));%%-----重建目标 Reconstruction the object-------------------%%%重建目标的原理参考全息术技术%%Reconstruction the object refer to principle of hologram%%------------------------------------------------------%image=hologram.*conj(ur);figure('name','phase map after illustrate');imshow(mat2gray(angle(image)));[imageR] = angulardiffraction(image,hx,hy,z,lambda);phiR=angle(imageR);imageR=abs(imageR).^2;figure('name','reconstruction');imshow(mat2gray(imageR));figure('name','phase of reconstruction');imshow(mat2gray(phiR));clear('hologram0');clear('hologram1');clear('hologram2');clear('hologram3');clear('image');clear('image_cut');clear('light0');