%GS算法
close all;
clc;
clear;
INput=imresize((imread('cameraman.tif')),[256,256]);
objectAmplitude=double(INput);
objectPhase=double(imread('input.png'));
objectPhase=2*pi*imresize(objectPhase,[256,256])./max(max(objectPhase));
object=objectAmplitude.*exp(1i*objectPhase);
Amplitude_object=abs(object);
FT_object=fftshift(fft2(object));
FT_object_amp=abs(FT_object);
%GS algorithm
[M,N]=size(object);
Phase=2*pi*rand(M,N);
for p=1:70
fxy=Amplitude_object.*exp(1i*Phase);
Fuv=fftshift(fft2(fxy));
Fuv_phase=angle(Fuv);
Fuv=FT_object_amp.*exp(1i*Fuv_phase);
fxy=ifft2(ifftshift(Fuv));
Phase=angle(fxy);
end
figure(1);imshow(Amplitude_object,[]);title('输入振幅');
figure(2);imshow(objectPhase,[]);title('输入相位');
figure(3);imshow(Phase,[]);title('复原相位');
评论2