%
% Make images for HW5 P2
%

%
% Make the low pass version of the image
%
X = ReadBin('girl2.bin',256);
figure(1);image(X);colormap(gray(256));axis('image','off');
title('Original Image','FontSize',18);

Uc = 64;

[U,V] = meshgrid(-128:127,-128:127);
HtildeCenter = double(sqrt(U.^2 + V.^2) <= Uc);
Htilde = fftshift(HtildeCenter);
H = fftshift(ifft2(Htilde));

figure(2);image(stretch(HtildeCenter));colormap(gray(256));axis('image','off');
title('HtildeCenter','FontSize',18);
figure(3);image(stretch(Htilde));colormap(gray(256));axis('image','off');
title('Htilde','FontSize',18);
figure(4);image(stretch(H));colormap(gray(256));axis('image','off');
title('H','FontSize',18);

ZPH = zeros(512,512);
ZPH(1:256,1:256) = H;
figure(5);image(stretch(ZPH));colormap(gray(256));axis('image','off');
title('ZPH','FontSize',18);

ZPX = zeros(512,512);
ZPX(1:256,1:256) = X;
figure(6);image(ZPX);colormap(gray(256));axis('image','off');
title('ZPX','FontSize',18);

ZPX2 = ifft2(fft2(ZPH) .* fft2(ZPX));

X2 = stretch(ZPX2(129:384,129:384));
figure(7);image(stretch(X2));colormap(gray(256));axis('image','off');
title('X2','FontSize',18);

figure(8);
image(stretch(log(1 + abs(fftshift(fft2(X))))));
colormap(gray(256));axis('image','off');
title('X FFT','FontSize',18);

figure(9);
image(stretch(log(1 + abs(fftshift(fft2(X2))))));
colormap(gray(256));axis('image','off');
title('X2 FFT','FontSize',18);
