Monday, August 9, 2010

Properties of 2D Fourier Transform



In this activity, 2D Fourier Transforms were introduced. Familiarization of its propetries were done via transformation of different 2D patterns.

Different image patterns were used to examine their fourier transforms. Their fourier transforms were displayed by taking its modulus.

Square Aperture
fft2() of the Square Aperture

Circular Aperture
fft2() of the Circular Aperture

Square Annulus
fft2() of Square Annulus


Two slits along x-axis
fft2() of Two slits along x-axis

Two dots
fft2() of Two dots.
Anamorphic property of Fourier transform.
To investigate in this property, a 2D sinusoid was used. This pattern is along the x-direction and is similar to the corrugated roof.
Using this code for sine:
z = sin(2*%pi*f*X);



Shown above is the pattern for the corrugated roof sinusoid with f = 1.

fft2() of the sinusoid.

By varying the value of f with values [0.5, 1, 15.14, 29.28, 43.42], the fft2() for looked like this:
f = 0.5
f = 1
f = 15.14
f = 29.28
f = 43.42

It seems that the separation is periodic too.

Since digital images have no negative values, a certain bias must be added to make those negative values readable. So, in the sinusoid generated with f = 10, a constant bias was added that is equal to 1. Taking its fft2(), it yielded this image.


Sinusoid with f = 10 and bias = 1.
fft2() of the generated sinusoid.

It is observed that there is a bright spot in the center. To be able to obtain the frequency of the pattern given an interferogram in the Young's double slit experiment, it can be regarded that the obtained fft2() is an interferogram. The bright spot in the center is filtered to be able to show the two dots obtained.These two dots contains the information needed to obtain the frequency. The frequency is related to the distance of the two dots.

Rotating the sinusoid patterns gave these images:


rotated 30 degrees
rotated 60 degrees
rotated 90 degrees
rotated 180 degrees

Taking their fft2(), it produced these images:
fft2() of rotated 30 degrees
fft2() of rotated 90 degrees
fft2() of rotated 90 degrees
fft2() of rotated 180 degrees

Using a combination of sinusoids in which the first one tranverses in the x-direction and the other one in the y-direction. It gave this fft2();
Combination of sinusoids in X and Y axes.
fft2() of combination of sinusoids in X and Y axes.

rotating them gave these results:



rotated 30 degrees
rotated 60 degrees
rotated 90 degrees
rotated 180 degrees

By taking their fft2(), it yielded these images:

fft2() of combination sinusoids rotated 30 degrees
fft2() of combination sinusoids rotated 60 degrees
fft2() of combination sinusoids rotated 90 degrees
fft2() of combination sinusoids rotated 180 degrees

Their fft2() is like the previous part of the single sinusoid rotated with the mirror projection of to the other side that resulted to a box with varying length and width.

I'd give myself 9/10 for this activity. It was really fun.

Sunday, August 8, 2010

Fourier Transform Model of Image Formation






In this activity, Fourier Transform was introduced. Fourier transform is a method of converting a certain object into the frequency space. In scilab, function as fft() and fft2() is used to discreetly transform a matrix into the fourier space. fft() means fast fourier transform. This algorithm has outputs interchanged. So, a certain fftshift() function is used to revert it to its original orientation.

Discreet FFT.
For familiarization of how fft() works, a certain 128x128 white circle with black background is subjected to fourier transforms.
Circle
after applying fft(), it looked like this:
FFT of Circle
using fftshift(), the image must revert to what is really the fft() of the figure
FFTshift of FFT of Circle
if another fft2() was applied to the newly transformed figure it will look like this:
Invers FFT of FFT of Circle

Using the letter A, it yielded these forms:

LetterA

FFT of LetterA
FFTshift of FFT ofLetterA
Inverse FFT of FFT of LetterA

It seems that if you inverse the fourier transform of the images, you will have the same image but inverted. :P

Convolution
Convolution of two images is like making the figure look like a little of both the two images. The convolution theorem is the multiplication of the fourier transform of the two images. Convolution is used in imaging devices, mostly in cameras. Usng this convolution method, an imaging device like a camera is simulated. The resulting image of the object to be taken and the aperture of the camera is simulated as follows:

Grayscale images of the word VIP and a white circle was convolved by obtaining the fft2() of the VIP image and the fftshift() of the circle. The two were multiplied and then the inverse fft() of the resulting product was obtained. Resulting images with varying circle size was seen as follows:


Initial Image of "VIP"Circle to simulate a small aperture

Circle to simulate a big aperture

Circle to simulate a medium sized aperture

Convolved images are as follows:

Convolution between the medium sized aperture and 'VIP'.

Convolution between the small sized aperture and 'VIP'
Convolution between the big sized aperture and 'VIP'

It can be seen that as the aperture gets bigger, a lot of light rays is allowed by the aperture. It results to a more defined structure of your resulting image. For a small aperture however, the image gets blurry due to the convolution of the circle and the image.

Correlation

Correlation measures up the degree of similarity between two function or images. For an even function, the correlation is the same as the convolution. That is why in this example, 128x128 pixel images were used.

In this part of the activity, template matching was done.This is a technique for finding the exactly identical patterns in a scene like finding a letter in a set of words.

128 x 128 images to be correlated.

This 128 by 128 pixel image with the caption 'THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN" and a 128 by 128 pixel images a the letter "A" with the same font size and style as in the previous image was used. The fourier transform of both images were obtained. The complex conjugate of text image and the fourier transform of A was multiplied. The inverse fourier transform of the resulting image was obtained. Resulting images was shown.

Correlated Images

Notice the bright spots? That is where A's are located. That's the first step in locating the patterns.

Edge detection

This is seen as the template mapping of an edge pattern with a template.
In this part, 3 patterns were used as the edge. They are as follows:

pattern1 = [-1 -1 -1; 2 2 2; -1 -1 -1];
pattern2 = [-1 2 -1; -1 2 -1; -1 2 -1];
pattern3 = [-1 -1 -1; -1 8 -1; -1 -1 -1];

with resulting images like this:


Pattern 1
Pattern 2
Pattern 3

After convolving them, It resulted these images:

Convolved VIP image with pattern 1
Convolved VIP image with pattern 2
Convolved VIP image with pattern 3

It seems that pattern3 has more matched sections of the image than other with respect to the number of bright sections seen in the image. It can also be sen that in pattern 2 an 1, there are black parts. They are somehow the resultant of the pattern and the section of the imaged that equaled to 0.

I think I'd give myself around 9/10 for this activity. Fourier transforms are cool.:)