%
% 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;
Sigma = 32;

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

X2tilde = Htilde .* fft2(X);

X2pure = ifft2(X2tilde);

X2 = stretch(X2pure);

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(X2);colormap(gray(256));axis('image','off');
title('X2','FontSize',18);



figure(6);
image(stretch(log(1 + abs(fftshift(X2tilde)))));
colormap(gray(256));axis('image','off');
title('X2pure FFT','FontSize',18);


%
% Make hi pass noise
%
N1 = random('norm',0,Sigma,256,256);

figure(5);image(stretch(N1));colormap(gray(256));axis('image','off');
title('N1','FontSize',18);

HtildeHi = double(sqrt(U.^2 + V.^2) > Uc);
N2 = ifft2(HtildeHi .* fft2(N1));

figure(7);image(stretch(N2));colormap(gray(256));axis('image','off');
title('N2','FontSize',18);


X3pure = X2pure + N2;

figure(8);image(stretch(X3pure));colormap(gray(256));axis('image','off');
title('X3pure','FontSize',18);






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

