Again in this activity, we made use of the Fourier Transform (FT) of an image. An image is treated as a superposition of sinusoids. And by applying FT on an image, we can obtain its spatial frequency. Every f(x,y) in an image has a corresponding F(k,l) in the Fourier space.
A. Anamorphic property of the Fourier Transform
For this part of the activity, we have a two dimensional signal and we take its FT. The steps are below:
//Creates a signal
nx = 100;
ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
f = 4 //frequency of the signal
z = sin(2*%pi*f*X);
imshow(z,[]);
And we obtain the figure below:
Figure 1: 2D signal with a f(frequency)=4
//Displays the FT of the signal
ft=fft2(z) // Takes the FT
imshow(fftshift(abs(z)), [ ] ); // Displays the magnitude of the signal
This will then display the figure below:
Figure 2: FT of signal with f=4
It can be observed in this figure that there are two dots lying on a vertical line. This two dots correspond to the frequency of the stripes in Figure 1. Midway between the dots is the DC value of the image. The DC value corresponds to the average frequency of the image. The dots are in a vertical line because the sinusoid's intensity vary vertically than horizontally.
The figure below shows the resulting FT for a signal with varying frequency.
Figure 3. Signals with f=2, 4, 10, 20
Figure 4. FT of signals with f=2, 4, 10, 20
It can be observed from Figure 4 that the distance between the stripes of the signal decreases as the frequency increases. Again, by taking the FT of the signal, we obtain its frequency, which is f=(1/distance between stripes), represented by the two dots. Since the frequency is inversely proportional to the distance of stripes, the separation between the two dots increases.
By choosing to rotate the sinusoid by an angle of 30 degrees:
nx = 100;
ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
f = 4;
theta = 30;
z = sin(2*%pi*f*(Y*sin(theta) + X*cos(theta)));
ft=fft2(z);
imshow(fftshift(abs(ft)),[]);
Figure 5: Theta = 30 , f=4
We obtained an image tilted by an angle of 120 degrees and its FT is also tilted by the same angle. Since the sinusoid's intensity vary most at this angle, then so does its FT frequency. Hence the FT shows us the frequency of the image and the direction where it varies most.
For the pattern below,
We used:
nx = 100;
ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
f = 4;
z = sin(2*%pi*4*X).*sin(2*%pi*4*Y);
ft = fft2(z);
imshow(fftshift(abs(ft)),[]);
Because the frequency of this image varies on the x and the y directions or diagonally, then so does its frequency.
B. Fingerprints
For this avtivity, we need to enhance the image of a fingerprint. The fingerprint that will be used is below.
im1 = imread("fingerprint.jpg");
f = im2gray(im1);
ft1 = fft2(f); // takes the ft of the image
ft2 = log(fftshift(abs(ft1))); // for smaller magnitude of ft
imshow(ft2, []);
This will display the FT of figure 8. We took the logarithm because the intensity of the Fourier image is large that we need to rescale it. Otherwise the resulting FT image will be black.
Figure 9. FT of fingerprint
From the image of the FT, we can design a filter. The goal is to let the bright part of the image through the filter to enhance the ridges.
Figure 10. Filter
After the filter is designed, we can think of them as the aperture. We then convolve the FT of the image with this filter.
im1 = imread('fingerprint.jpg');
im2 = imread('filter.jpg');
fprint = im2gray(im1);
filter = im2gray(im2);
ft1 = fft2(fprint); // takes the ft of the image
FP = log(fftshift(abs(ft1))); // for smaller magnitude of ft
F = fftshift(filter);
FPF = ft1.*F; // convolve the images
final = ifft(FPF);
last = real(final);
imshow(last, [ ]);
The result is below:
The result is obtained via trial and error. Because the goal is to obtain all the necessary information about the image and at the same time remove the unnecessary ones. I also tried using a matrix pattern but since the background of the image is uneven, using matrices to enhance the ridges also enhances the lines present in the background.
C. Lunar Image
For this part of the activity, the goal is to remove the vertical lines in the figure below.
Using a code similar to part B,
stacksize(20000000);
im1 = imread('moon.jpg');
im2 = imread('filter1.jpg');
moon = im2gray(im1);
filter = im2gray(im2);
ft1 = fft2(moon); // takes the ft of the image
M = log(fftshift(abs(ft1))); // for smaller magnitude of ft
F = fftshift(filter);
MF = ft1.*F; // convolve the images
final = ifft(FPF);
last = real(final);
imshow(last, [ ]);
The FT of the image is,
And the filter used was,
Finally, we obtained the enhanced image.
I also used the filter below,
and the resulting image is:
which in my opinion is the same as the as the other enhanced image.
I rate myself 10/10 for this activity because it took me a lot of time to figure out what to do.
Thanks Beth for helping me in this activity.
Reference:
http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm
No comments:
Post a Comment