Showing posts with label fourier transform. Show all posts
Showing posts with label fourier transform. Show all posts

Thursday, July 9, 2009

Activity 6 | Properties of the 2D Fourier Transform

Previously in Activity 5, we applied image processing techniques involving the Fourier Transform such as edge detection and template matching using convolution and correlation. Now we investigate further the properties of the 2D Fourier Transform. The properties to investigate are that the Fourier Transform expresses any signal or image into a superposition of sinusoids and that the rotation of the sinusoids result to the rotation of the Fourier Transform.[1]

Before anything else let us familiarize the Fourier Transforms of some 2D patterns (left) namely a square, an annulus or donut, a square annulus, two slits, and two dots along the x-axis that are symmetric about the center which are shown below together with their corresponding FTs (right) shown in Figure 1.

Figure 1. 2D patterns and their corresponding Fourier Transforms.

Now we investigate the anamorphic property of the Fourier Transform through the investigation of the superposition and rotation of sinusoids and their FTS in relation to the FT of different 2D patterns.

We create a 100x100 sinusoid with frequency f = (1, 4, 16) and get the modulus of its Fourier Transform. The images in Figure 2 show the produced 2D sinusoids (upper row) and their corresponding FTs (lower row) with increasing frequency values from left to right. The Fourier Transform of a 2D sinusoid results to an image with a peak at the frequency (+f or -f) of the said sinusoid thus we see two points along the axis of the sinusoid and symmetric from the center which is f = 0. As the frequency increases, the distances between the two points increases as expected. Code is taken from the AP186 Activity 6 sheet.

nx = 100; ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
f = 1; //frequency
z = sin(2*%pi*f*X);
imshow(z, []);



Figure 2. 2D sinusoids with frequencies f = 1, 4, and 16 and their corresponding FTs.

Figure 3 shows how the Fourier Transform of the resulting sinusoids would look like if a constant bias (upper row) or another sinusoid of low frequency (lower row) is added to the original sinusoids shown in Figure 2. The frequency order is the same as in Figure 2.



Figure 3. Fourier Transform of a sinusoid with a constant bias (upper row) or with an added low frequency sinusoid (lower row.)

Adding a constant bias to the original sinusoids resulted to the addition of a peak (which is the bias) at f = 0 to the respective Fourier Transforms of the sinusoids. If another sinusoid is added to a sinusoid the FT will show the frequencies of the two sinusoids like if a sinusoid with f=4 is added with a sinusoid with f=1 then their FT will show a peak at f=4 and f=1.

Rotating the sinusoids will also rotate their FTs as shown in Figure 4 for theta = 30, 45, and 60. Then we combine these rotated sinusoids to make patterns.



Figure 4. Rotated sinusoids (upper row) with f = 4 and the FTs (lower row) at theta = 0, 45, and 60 degrees respectively.

Now if we combine a sinusoid running in the x direction with another running in the y direction by addition or multiplication we get patterns as shown by Figure 5 below. Their FTs are just the superposition of their individual FTs. The code that generated these combinations are the following:

z_sum = sin(2*%pi*4*X) + sin(2*%pi*4*Y);
z_prod = sin(2*%pi*4*X) * sin(2*%pi*4*Y);
z_prod2 = sin(2*%pi*4*X). * sin(2*%pi*4*Y);




Figure 5. Combinations of a vertical and horizontal sinusoid using the equations shown above and their FTs.

If we add series of arbitrary rotated sinusoids to the patterns in Figure 5 we get patterns that looks like twisted checkered patterns as shown in Figure 6 below. The FTs of the patterns below is the same as the predicted results except for the matrix multiplication (middle row) where its FT is the same as the original pattern. It can be observed that the pattern itself has little deviation from the original pattern. As for the addition and the element by element multiplication, their FTs is the same as predicted which will be again, a superposition of the FTs of the original pattern and the added rotated patterns. If the added rotated sinusoids have rotations that scan from 0 t0 90 degrees in small increments then we expect a circle to form in the FT of that image which is partially shown by the FTs for the addition and the element by element multiplication.




Figure 6. Combinations of a vertical and horizontal sinusoids added with arbitrary rotated sinusoids and their corresponding FTs.

I give myself a 10 for this activity since the FTs produced were correct and they matched what was expected.

Tuesday, July 7, 2009

Activity 5 | Fourier Transform Model of Image Formation

The Fourier Transform is one of the basic transforms used in imaging and is implemented in a fast and efficient way by the Fast Fourier Transform or FFT which is also mainly used in signal processing. The FFT is available in many signal and image processing software like the one used in this activity which is Scilab. The fft2() function in Scilab performs the Fast Fourier Transform for any two-dimensional signal or for this activity, images. Analyzing and processing images is explored using the the Fast Fourier Transform, convolution used in edge detection and correlation used in template matching.

5A - Familiarization with Discrete FFT

In the first part of the activity we get to familiarize the built-in function fft2() by applying it to a 128x128 image of a white circle on black background and the letter A that is constructed using Paint. Then we apply fftshift() to get the Fourier Transform of the image. The Fourier Transforms obtained agree with the analytical Fourier Transform of a circle which is an airy disk that becomes a airy point when the circle is large while for the letter A, it is like the Fourier Transform of a triangle that has three lines crossing each other at the center.

If we take the FFT of the resulting FFT of the images we get the intensity image or the original image that is inverted as shown by the last row of images. What is expected after getting the Fourier transform of the Fourier transform of the original image is the original image itself but inverted since an fftshift() is applied after the first FFT.



Original
image
FFT of
image
Shifted
FFT image
FFT of
FFT of
image


5B - Simulation of an Imaging Device

In this activity we simulate an imaging device - the lens - by using FFT and convolution where a function is operated on another function to get a new function. The object is a 128x128 image of the letters VIP in Arial which will serve as the first function and the aperture of the lens is a 128x128 image of a circle and its transfer function will be the second function. The convolution of these two functions will give the image produced by this system. The Fourier Transform is the lens in this system such that by doing a convolution between the Fourier Transforms of the object and the aperture you get the produced image of the system. Below are the images used and produced in this activity.


Different sizes of aperture are used as shown by the different sizes of circle images. It can be seen that as the aperture size becomes larger, the produced image becomes clearer and more defined. This agrees with the fact that small, finite apertures can't get or capture all light coming from the object thus a blurring is observed in the resulting image.

5C - Template Matching Using Correlation

Another method used in signal and image processing is correlation that is similar to convolution such that it is also related to the complex conjugation of the Fourier Transforms of the desired signals. Correlation measures the degree of similarity between two signals thus making it useful for checking patterns like for this activity where an image containing a phrase is correlated with another image containing the letter A. This letter A will be the template or the pattern.


The resulting image after the correlation shows the highest values, with black=0 and white=1, are at areas where the letter A can be found.

5D - Edge Detection Using the Convolution Integral

Edge detection is also like template matching only a pattern is used and that pattern is convolved with the VIP image using the built-in function imcorrcoef() in Scilab SIP Toolbox. Below are the resulting images using different patterns such as vertical, horizontal, diagonal, back diagonal, and spot pattern.

The images at the right side show the areas that are highly similar to the respective pattern. Say for example for the vertical and horizontal patterns, in the resulting image, the most pronounced areas are the edges that are vertical and horizontal respectively. The horizontal and vertical lines especially in the letters I and P are gone respectively for the vertical and horizontal pattern. Lastly, among the five patterns used, the spot pattern is the one that gave the best edge detection since it does not suggest any specific direction and it is like tracing the edge pixels of the letters V, I, and P.

I'd like to give myself a grade of 10 for this activity because it was fairly easy since the codes are already given but I give myself a grade of 9 for this activity because I did not finish the blog on time. Also I had a hard time exporting quality images from my results since I did not know anything about the command imwrite() but I thank Mr. Miguel Sison for mentioning it so I was able to apply it to the last part of the activity. It is a lot easier and the image quality is better.

Reference - UPNIP - AP186 - Activity Sheet 5 - Fourier Transform of Image Model.