clear all; close all;
I = imread('batman.gif', 'gif');
I = double(I);
I = I./max(max(I));
avgl=mean(mean(I));
figure; imshow(mat2gray(I));
title('Original Object');
figure;
axis([0 , 101, 0, 1]);
xlabel ('Number of Iterations')
ylabel ('RMSE')
hold on
I1 = I;
for n=1:101;
H = fftshift((fft2(fftshift(I1))));
I2 = fftshift(fft2(fftshift(exp(1j.*angle(H)))));
avg2=mean(mean(abs(I2)));
I2=(I2./avg2).*avgl;
rmse=mean(mean((abs(I2)-I).^2))^0.5;
plot(n,rmse,'o');
pause(0.00001);
I1=I.*exp(1j*angle(I2));
end
figure; imshow(H);
colormap gray
ti = get(gca,'TightInset')
set(gca,'Position',[ti(1) ti(2) 1-ti(3)-ti(1) 1-ti(4)-ti(2)]);
set(gca,'units','centimeters')
pos = get(gca,'Position');
ti = get(gca,'TightInset');
set(gcf, 'PaperUnits','centimeters');
set(gcf, 'PaperSize', [pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition',[0 0 pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
imwrite(H, 'SupermanPhaseMask2.gif')
hold off
I2=I2./max(max(abs(I2)));
figure; imshow(abs(I2));
title('Reconstucted Image')