TP1 Final Report IP
TP1 Final Report IP
Group:
M1 E3A Lab 1
Exercise 1: Interpretation of frequency content
1. Calculate the centered Fourier transform of an image of your choice in grayscale.
clear all
% Load the image
image = imread('image4.jpg');
img_col = image;
1
% Convert the image to double precision for Fourier transform
image = im2double(image);
2
2. Where are the low frequencies, the high frequencies, the coefficients having the greatest amplitude?
Comment on the spectral content. Test on several images. Comment according to the frequency content of the
images.
The low frequencies are located in the centre of the image, the high frequencies in the surroundings of
the image and for this image, the coefficients that carry the greatest amplitude are the ones located in low
frequencies having in (0,0) the highest value which is the sum of the image elements.
3. Find the average of the gray levels of the image using the Fourier transform.
We will use:
3
Exercise 2: Properties of the Fourier Transform
Check the following properties of the discrete 2D Fourier transform on the image of your choice. When
necessary, be sure to create the appropriate images in terms of content but also in terms of size.
1. Linearity
if size(image2, 3) == 3
image2 = rgb2gray(image2);
end
% Convert the image to double precision for Fourier transform
image1 = im2double(image1);
image2 = im2double(image2);
%Defining constants
A = 2;
B = 3;
figure;
imagesc(module_dif);
colormap jet;
colorbar;
title('Lineatiry: Proof Fourier Transform of difference');
4
We can say that the linearity property is demonstrated due to the fact that from the Fourier transform graph the
difference between the values of f_image1 and f_images2 is almost zero.
2. Rotation
subplot(2, 2, 2);
imshow(rotated_image);
title('Rotated Image');
5
subplot(2, 2, 3);
imagesc(log(1 + abs(f_image)));
colorbar;
title('Fourier Transform of Original Image');
subplot(2, 2, 4);
imagesc(log(1 + abs(f_rotated_image)));
colorbar;
title('Fourier Transform of Rotated Image');
The rotation property says that if an image is rotated, then its Fourier Tranform will be rotated too. This property
is shown on the graphics above.
figure;
imagesc(log(1 + abs(f_shifted_image)));
colormap jet;
colorbar;
title('Fourier Transform of Shifted Image');
6
According to the Fourier Transform of Shifted Image, it is seen that the frequency values are translated from the
center to the edges.
If and
And:
7
1. A sinusoid function
subplot(1, 2, 2);
imagesc(log(1 + abs(f_image)));
colorbar;
title('Fourier Transform of Sinusoid Image');
end
end
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
From the analysis of the fourier transform of sine, it is seen that according to the values of A and B the dirac
function is placed in a certain frequency.
26
Fourier transform of the sine function given:
2. A gate function
% Display the original gate function image and its Fourier transform
figure;
subplot(1, 2, 1);
imshow(gate_image);
title('Gate Function Image');
subplot(1, 2, 2);
imagesc(log(1 + abs(f_gate_image)));
colorbar;
title('Fourier Transform of Gate Function Image');
figure;
plot(abs(f_gate_image(floor(size(f_gate_image,1)/2),:)))
title('Side view of the fourier transform of sine')
27
It is seen that the fourier transform of the gate function is the sinc function with maximum value in the origin.
3. A Gaussian (fspecial)
subplot(1, 2, 2);
imagesc(log(1 + abs(f_gaussian_filter)));
colorbar;
title('Fourier Transform of Gaussian Filter');
28
figure;
plot(abs(f_gaussian_filter(floor(size(f_gaussian_filter,1)/2),:)))
title('Side view of the fourier transform of gauss function')
29
It is seen that the fourier transform of the gauss function is another gauss function, but with a bandwith reduced
and which is inversely proportional to the standard deviation of the gauss function in the spacial domain.
% Display the original uniform average filter and its Fourier transform
figure;
subplot(1, 2, 1);
imshow(uniform_average_filter, []);
title('Uniform Average Filter');
subplot(1, 2, 2);
imagesc(log(1 + abs(f_uniform_average_filter)));
colorbar;
title('Fourier Transform of Uniform Average Filter');
30
figure;
[~,ind_max]=max(max(f_uniform_average_filter));
plot(abs(f_uniform_average_filter(ind_max,:)))
31
It is seen that the fourier transform of the uniform average filter is the delta dirac function centered in the origin.
subplot(1, 2, 2);
imagesc(log(1 + abs(f_laplacian_filter)));
colorbar;
title('Fourier Transform of Laplacian Filter');
32
figure;
plot(abs(f_laplacian_filter(floor(size(f_laplacian_filter,1)/2),:)))
33
It is seen that the fourier transform of the laplacian filter is a triangular function which has the minimum in the
origin.
figure;
subplot(1, 2, 1);
imagesc(log(1 + abs(f_convolution)));
colorbar;
34
title('Fourier Transform of Conv in Spacial domain');
subplot(1, 2, 2);
imagesc(log(1 + abs(M)));
colorbar;
title('Multiplication in frequency domain');
According to the corresponding graphs plotted, it can be seen that the two graphs look alike. This is a
demonstration of how a convolution in the spatial domain is equivalent to a multiplication in the frequency
domain.
Exercise 5: Sampling
1. Calculate the Fourier transform of a pulse train of the period of your choice. To generate an image 256 × 256
with a pulse train of period 4 pixels:
35
f_pulse_train = fftshift(fft2(pulse_train));
figure;
imagesc(log(1 + abs(f_pulse_train)));
colorbar;
title('Fourier Transform of pulse train');
2. Sample the image of your choice then the UCSB image using the generated pulse train. Note: multiply the
image with the pulse train.
%Sampling
sampled_image = image1.*pulse_train;
3. Calculate the 2D DFT of the sampled image. Make the link with the theoretical results seen in class.
36
subplot(1, 2, 2);
imagesc(log(1 + abs(f_sampled_image)));
colorbar;
title('Fourier Transform of sampled image');
It is seen from the graph that the fourier tranform of a pulse train is another pulse train but in frequency domain
and between each pulse there is a distance of fs which is the sampling frequency or the inverse of the pulse
train period.
Sampling the image will give a result in frequency domain of the fourier tranform of the image repeated multiple
times through the frequency domain each sampling frequency fs.
4. Suggest a way to find the original image from the sampled image knowing that the sampling highlights the
phenomena of Aliasing. You are not asked to implement the proposed solution.
When an image is sampled, aliasing occurs when the sampling rate is insufficient to capture all the details in the
original image. Aliasing can result in distorted or "jagged" images that are difficult to interpret.
There are various anti-aliasing techniques that can be used to improve the quality of a sampled image,
including:
37
• Oversampling: This involves increasing the sampling rate of the image to reduce the aliasing effects. The
image is then down-sampled to its original resolution.
• Filtering: Applying a low-pass filter to the sampled image can remove high-frequency components that
cause aliasing. The filtered image is then down-sampled to the original resolution.
frequencies (0.25, 0.5, etc.). Reminder: , where n is the order of the filter, D0 the
len_row = size(f_image1,1);
len_col = size(f_image1,2);
[u, v] = meshgrid(-floor(size(image1,2)/2):floor(size(image1,2)/2)+rem(size(image1,2),2)-1, -fl
D = sqrt(u.^2 + v.^2);
D0 = [10 30 50]; %Defining the cutoff frequencies
len_D0 = size(D0,2);
LPF = ones(len_row,len_col,len_D0);
H = zeros(len_row,len_col,len_D0);
n = 1;
for i=1:len_D0
%Ideal Low pass filter
LPF1 = LPF(:,:,i);
LPF1(D > D0(i)) = 0;
LPF(:,:,i) = LPF1;
%Filtering
for i=1:len_D0
f_image1_LPF = LPF(:,:,i) .* f_image1;
filtered_image1_LPF = real(ifft2(ifftshift(f_image1_LPF)));
figure;
filtered_image1_butter = real(ifft2(ifftshift(H(:,:,i).*f_image1)));
imshowpair(filtered_image1_LPF, filtered_image1_butter,'montage')
title('Filtered image Ideal LPF Vs. Filtered Image Butterworth LPF cutoff freq= '+string(D0
38
end
figure;
imshowpair(log(1 + abs(LPF(:,:,len_D0))), log(1+abs(H(:,:,len_D0))),'montage')
title('Fourier Transform Ideal LPF(Left) Vs. Fourier Transform Butterworth LPF(Right)')
39
The operation of low pass filtering attenuates components that have a high frequency in the image, leaving the
resting low-frequency components on the image, giving as a result a blurry image. The distintion between the
low frequencies and high frequencies is established by the cutoff frequency.
The difference one can arrive between the Butterworth and ideal low pass filter is that the Butterworth filter does
not supress the high frequencies at all. So, it makes the images less blurry than using the ideal low pass filter
but it is still able to supress the noise involved.
for i=1:len_D0
%Ideal High pass filter
HPF1 = HPF(:,:,i);
HPF1(D <= D0(i)) = 0;
HPF(:,:,i) = HPF1;
end
%Filtering
for i=1:len_D0
filtered_image1_HPF = real(ifft2(ifftshift(HPF(:,:,i) .* f_image1)));
filtered_image1_butter = real(ifft2(ifftshift(H(:,:,i).*f_image1)));
figure;
imshowpair(filtered_image1_HPF, filtered_image1_butter,'montage')
title('Filtered image Ideal HPF Vs. Filtered Image Butterworth HPF cutoff freq= '+string(D0
end
40
figure;
41
The operation of high pass filtering attenuates components that have a low frequency in the image, leaving
the resting high-frequency components on the image, giving as a result an image where one can notice the
edges enhanced. The distintion between the low frequencies and high frequencies is established by the cutoff
frequency.
The difference one can arrive between the Butterworth and ideal high pass filter is that the Butterworth filter
does not supress the low frequencies at all. So, it makes the images less blurry than using the ideal high pass
filter and it makes it difficult to detect the edges as we can se in the plotted results.
42