% Fig. 4.48
% Gaussian lowpass filter

clear all;
close all;
f = imread('Fig0448(a)(characters_test_pattern).tif');
imshow(f,'initialmagnification','fit');

PQ = paddedsize(size(f));
[U,V] = dftuv(PQ(1), PQ(2));

% Represent the image in frequency domain
F = fft2(f, PQ(1), PQ(2));
% Display the spectrum as an image
figure; 
imshow(log(1 + abs(fftshift(F))), [],'initialmagnification','fit');

% Generate the Gaussian filter
D0 = 0.05*PQ(2);   % 5% of the padded image width
H = exp(-(U.^2 + V.^2) / (2*(D0^2)));

% View the filter as an image (after shift to the center)
figure; imshow(fftshift(H),[],'initialmagnification','fit');

% Apply the filter to the image
g = dftfilt(f, H);
% Show the output image
figure, imshow(g,[],'initialmagnification','fit');

    