%	h1template.m
%	Template for image filtering using 2D FFT

rect = inline('abs(x) < 1/2');	% handy function

nx = ?;	ny = ?;			% sampling parameters
dx = ?;	dy = ?;
x = [-nx/2:nx/2-1] * dx;
y = ?
? = ndgrid ?			% sampling grid
fxy = ?				% (samples of) the image f(x,y)
clf, subplot(231)		% display the image
imagesc(x,y,fxy'), axis image, axis xy, colorbar
xlabel x, ylabel y, title 'f(x,y)', colormap(1-gray(256)) % saves toner

%	find the 2D FFT of the image
%	hint: fftshift() will be important somewhere near here!
F = ?	
u = ?				% frequency sample positions (f_X) 
v = ?				% frequency sample positions (f_Y) 

subplot(234)			% display the spectrum of f(x,y)
imagesc(u, v, abs(F)'), axis image, axis xy
xlabel u, ylabel v, title 'F(u,v)', colorbar horiz

%	Create (samples of) filter frequency response, and display
H = ?

subplot(235), imagesc(u, v, H'), axis image, axis xy
xlabel u, ylabel v, title 'H(u,v)', colorbar, horiz

%	Find spectrum of output image using convolution property of 2D FT
G = ?

%	Find final image by returning to image domain
%	Watch out for fftshift() again!
gxy = ?

%	display real and imaginary parts of g(x,y)
subplot(233), imagesc(x, y, real(gxy)'), axis image, axis xy
xlabel x, ylabel y, title 'Re[g(x,y)]', colorbar

subplot(236), imagesc(x, y, imag(gxy)'), axis image, axis xy
xlabel x, ylabel y, title 'Im[g(x,y)]', colorbar horiz
%	Hint: does your imaginary part make sense?

frac = max(abs(imag(gxy(:)))) / max(abs(gxy(:)))    % check imaginary part
