N=512;A=zeros(N,N);B=zeros(N,N);forI=1:1:256J=1:1:256ImageNum=double(Image(I,J,1));A(I,J)=ImageNum/255;B(I,J)=0;endendfigure;imshow(A);pi=3.1415926;forI=1:1:NforJ=1:1:NR=rand(1,1);%生成一个元素在0,1之间均匀分布的随机矩阵RB(I,J)=A(I,J)*sin(R*2*pi);%平滑函数的傅里叶变换谱A(I,J)=A(I,J)*cos(R*2*pi);F(I,J)=A(I,J)+j*B(I,J);endEnd%限制振幅的动态范围,进步编码的精度F=fft2(F);%作二维快速傅里叶变换FFTMax=max(max(abs(F)));F=F/Max;A=real(F);B=imag(F);aIpha=0.5;%定义载波参数aIphaforI=1:1:NforJ=1:1:NXcos=(J-1)/127;A1(I,J)=cos(2*pi*aIpha*Xcos);B1(I,J)=sin(2*pi*aIpha*Xcos);endend%全息图数据区forI=1:1:NforJ=1:1:NHoIodata(I,J)=0.5+0.5*(A(I,J)*A1(I,J)+B(I,J)*B1(I,J));endEndM=512;N=512;%定义全息图的大小Hologram=zeros(M,M);S=M/N;%定义每个抽样单元大小forI=1:1:NforJ=1:1:NXa=(J-1)*S+1;Xb=J*S;Ya=(I-1)*S+1;Yb=I*S;forIx=Xa:1:XbforIy=Ya:1:YbHoIogram(Iy,Ix)=HoIodata(I,J);endendendendMax=max(max(HoIogram));HoIogram=HoIogram/Max;figure;imshow(HoIogram);%以下是用matlab分别计算函数各抽样点的傅里叶变换谱的幅角与模,并对各点的模归一化object=fft2(HoIogram);object=fftshift(object);%用matlab中的移谱函数fftshift()将频谱的低频成分移到中心,以避免再现时像分散在边缘object=abs(object);object=1000*object/max(max(object));figure;imshow(object);
2019/5/1 5:12:10
973B
数字全息
1