N=512;
A=zeros(N,N);
B=zeros(N,N);
for I=1:1:256
J=1:1:256
ImageNum=double(Image(I,J,1));
A(I,J)=ImageNum/255;
B(I,J)=0;
end
end
figure;
imshow(A);
pi=3.1415926;
for I=1:1:N
for J=1:1:N
R=rand(1,1);%生成一个元素在0,1之间均匀分布的随机矩阵R
B(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);
end
End%限制振幅的动态范围,提高编码的精度
F=fft2(F);%作二维快速傅里叶变换FFT
Max=max(max(abs(F)));
F=F/Max;
A=real(F);
B=imag(F);
aIpha=0.5;%定义载波参数aIpha
for I=1:1:N
for J=1:1:N
Xcos=(J-1)/127;
A1(I,J)=cos(2*pi*aIpha*Xcos);
B1(I,J)=sin(2*pi*aIpha*Xcos);
end
end%全息图数据区
for I=1:1:N
for J=1:1:N
HoIodata(I,J)=0.5+0.5*(A(I,J)*A1(I,J)+B(I,J)*B1(I,J));
end
End
M=512;N=512;%定义全息图的大小
Hologram=zeros(M,M);
S=M/N;%定义每个抽样单元大小
for I=1:1:N
for J=1:1:N
Xa=(J-1)*S+1;
Xb=J*S;
Ya=(I-1)*S+1;
Yb=I*S;
for Ix=Xa:1:Xb
for Iy=Ya:1:Yb
HoIogram(Iy,Ix)=HoIodata(I,J);
end
end
end
end
Max=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-12-21 20:52:45
973B
数字全息
1