0% found this document useful (0 votes)
27 views4 pages

Fourrier Lab Maher Nadar

Uploaded by

Chirag Dua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Fourrier Lab Maher Nadar

Uploaded by

Chirag Dua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Maher Nadar

Advanced Topics in Computer Vision


Practice1 Frequency domain filtering
Problem 1: Notch Filters to remove noise

In this problem, the objective is to remove periodic noise present in an image by means of the Fourier transform.

We start off with the original image ('moon.jpg'), separately generate a periodic (sinusoidal) noise along the
vertical direction and then merge the two components together to obtain the image with noise:

% Generating the noise matrix


I2 = zeros(size(1),size(2));
noise_freq1 = 1/8;
for i=1:size(1)
I2(i,:) = sin(i*noise_freq1)*127; % Sinusoidal noise
End

noise_image = imfuse(I,I2,'blend');

After that, we compute the Fourier transform of the original and the noise image, shift the result to the centre and
display the spectrums in order to visualize (and compare) the frequency representation of the noise.

In the spectrum of the noise image, the task now is to eliminate these bright spots that represent the periodic noise.
We generate a loop that searches for the pixels inside the spectrum that have absolute values beyond 0.6*the
maximum value. These pixels correspond to the same pixels in the Fourier transform that represent the noise, so we
have to eliminate them to enhance the quality of the image. However, we need to read the central bright part of the
frequency in order to keep the high frequencies corresponding to the original image:
% analysing the spectrum and deleting (zeroing) the pixels of the bright
frequencies in the Fourier transform accordingly

for i = 1:size(1)
for j = 1:size(2)
if abs (s2(i,j)) > max(max(abs(s2)))*0.6
f7s(i,j) = 0;
end
end
end

% restoring the central high frequencies in the Fourier transform

for i = size(1)/2 - 4: size(1)/2 + 4


for j = round(size(2)/2) - 4: round(size(2)/2) + 4

f7s(i,j) = f7s2(i,j);
end
end

Next, we need to invert the shift done in the Fourier transform and invert the Fourier transform itself in order to get
back to the image format and check the result of our cleaning process:

F = ifftshift(f7s); % inverse shift og the fourrier


clean_image = real(ifft2(F)); % inverse of the fourrier transform
Problem 2: Where is the information? In the Magnitude or in the Phase?

In this problem, the objective is to figure out which part of the frequency transform (magnitude or phase) is the

most dominant or contains most of the information about the image display. In order to do that, we first read two

images ('elephant.jpg') and ('truck.jpg'), and transform them to grey scale. After that, we get their

Fourier transforms and obtain their respective magnitudes and phases:

i1 = imread('elephant.jpg');% reading the images of elephant and truck


i2 = imread('truck.jpg');

i1 = rgb2gray(i1); % converting the images to gray scale


i2 = rgb2gray(i2);

% elephant frequency transformation

f1 = fftn(i1); % obtaining the frequency transform of the image


mag1 = abs(f1); % obtaining the magnitude from the frequency
s = log(1+fftshift(f1)); % obtaining the spectrum of frequency
phase1 = angle(f1); % obtaining the phase from the frequency

% truck frequency transformation

f2 = fftn(i2);
mag2 = abs(f2);
s2 = log(1+fftshift(f2));
phase2 = angle(f2);

a) magnitude of truck; b) magnitude of elephant ; c) phase of truck; d) phase of truck


Next, we merge the phase of the elephant with the magnitude of the truck and vice versa. We invert the shift and
the Fourier in order to obtain the resulting mixed images, taking into consideration that the complex values in the
Fourier domain are represented as

, where r is thee magnitude and θ is the phase:

f3 = mag1.*exp(1i*phase2); %merging the elephant magnitude witht the


mag_elephant_phase_truck = ifft2(f3); %inverse crossed transformation

f4 = mag2.*exp(1i*phase1);
mag_truck_phase_elephant = ifft2(f4);

Results:

As we can observe in the last image, the dominant parameter in the Fourier transform is the phase compared to the

magnitude. In fact we can recognise the elephant in the mix where the elephant phase is present, and similarly for

the truck.

You might also like