Showing posts with label FFT. Show all posts
Showing posts with label FFT. Show all posts

Saturday, July 11, 2009

A6 PROPERTIES OF THE 2D TRANSFORM

In A5 we familiarized ourselves with the 2D transform. In this activity we take a more in depth look at some of the properties of the 2D transform.


A6A Familiarization with FT of Different 2D Patterns


The FT of a 2D image will give us the resulting diffraction pattern for an aperture of the same shape. It is therefore important to familiarize ourselves with the FT of some common 2D patterns.


Annulus


The FT of an annulus looks like the FT of a circle (Airy disk) with some of the fringes missing.



Figure 1


Square


Mathematically, the FT of a square are sync functions along the x and y axes. This can be seen below.




Figure 2


Square Annulus


The FT is similar to that of the square, but with some fringes missing.




Figure 3

Two Slits

This is actually a simulation of Thompson Young’s Double slit experiment, and our results agree with the experimental results.



Figure 4


Two Dots


The FT looks like that of the circle but with vertical fringes due to destructive interference from the signals coming from the two dots.


Figure 5


The 2D patterns are generated in Scilab using the following code


/////// 6A

x = [-1:0.01:1];

[X,Y] = meshgrid(x);

/////////// annulus

r = sqrt(X.^2 + Y.^2);

annulus = zeros(size(X,1), size(X,2));

annulus(find (r <=0.3 & r>=0.2)) = 1.0;

////// square

square= zeros(size(X,1), size(X,2));

square(find(abs(X)<=0.4 & abs(Y) <=0.4 ))=1.0;

////// square annulus

square2=square;

square2(find(abs(X)<=0.25 & abs(Y) <=0.25 ))=0.0;

//////slits

slits= zeros(size(X,1), size(X,2));

slits(find(abs(X)>=0.47 & abs(X) <=0.5 ))=1.0;

//////dots

r1 = sqrt((X-0.5).^2 + Y.^2); r2 = sqrt((X+0.5).^2 + Y.^2);

dots = zeros(size(X,1), size(X,2));

dots(find (r1 <=0.05 )) = 1.0; dots(find (r2 <=0.05 )) = 1.0;

image=dots;

subplot(1,2,1);

imshow(image,[]);

subplot(1,2,2);

imshow(fftshift(abs(fft2(image))),[]);


A6B Anamorphic Property of the Fourier Transform


The FT of a sinusoid is two peaks located at its positive and negative frequency values. Increasing the frequency therefore makes the peaks farther apart. We can also say that because the spacing between dark and light bands becomes narrower, since the FT is in inverse space, the spacing between the peaks will be wider. This is shown in the images below. The images in the first row are the sinusoids while those below are the FTs.



Figure 6

Real digital images do not have negative values. Therefore if we want to simulate a digital image, we must add a constant bias to our sinusoids.


Figure 7

The results of the FTs when bias is added to the sinusoid are shown above. As we can see, no matter what the constant bias, its FT will always be a peak in the origin. So to find the frequency of the sinusoid we just have to ignore the central frequency.


The same is true when the bias is a sinusoid with very low frequencies. We already demonstrated above that the lower the frequencies, the closer to the origin the peaks will be. The image below is the FT of a sinusoid with frequency = 4 with a sinusoid bias of frequency = 0.25. The peaks of the original sinusoid are unchanged; however, there are now to extra peaks very close to the origin and almost looking like the single peak of the constant bias. Therefore to find the original frequencies we also just ignore the central and “almost” central frequencies.


Figure 8

In the 2D FT a rotation of the sinusoids results to a rotation in the FTs. This is shown below. The sinusoid is rotated from 0˚ to 45˚ to 90º to 135º.




Next we created a pattern of sinusoids in x and y using the following formula

sine = sin(2*%pi*4*X).*sin(2*%pi*4*Y). The resulting pattern and FT are shown below.



Figure 10

We then added several rotated sinusoids to this pattern and predict the FT. Knowing that the FT has the property of linearity, we can predict that adding the sinusoids from Figure 9 to the sinusoid in Figure 10 will result to just the superposition of their FTs. Taking the actual FTs, we indeeed had correct predictions.

Figure 11

Then just for fun, I tried adding all the sinusoids together.



Figure 12


In this activity, I understood all that I did so I give myself a grade of 10.

Monday, July 6, 2009

A5 Fourier Transform Model Of Image Formation

This activity is a demonstration of the many uses of the Fourier Transform.

We did this part by part and here are my results.


5.A FAMILIARIZATION WITH DISCRETE FFT


The FFT of an image is a transformation into inverse space or spatial frequency.

The function is built into Scilab and here are our results when fft2 is applied to a circle and to the letter A.

Original Image




FFT and zoomed Shifted FFT


FFT of FFT


Original Image



FFT and zoomed Shifted FFT




FFT of FFT

The output of fft2 has the quadrants along the diagonals interchanged; therefore fftshift is needed to realign the quadrants back. As expected the fft of a circle resulted to an Airy disk. Applying fft2 twice just resulted to an inverted copy of the original image.


5.B SIMULATION OF AN IMAGING DEVICE


The convolution model predicts the image produced when an object is viewed using an imaging sytem. Convolution is the smearing of one function with another such that the resulting function looks a little like both. In Fourier space, the product of the FTs of the image and the imaging system will give us the FT of the resulting image.

To simulate, we used the word “VIP” for our image and a circle to represent the aperture of an imaging device.

Original Image




We then applied fft2 to the image and fftshift to the aperture since the aperture is already in Fourier plane). The results after convolving are shown below. It was observed that as the diameter of the aperture gets bigger, the image becomes sharper. This is because a larger circle results to a smaller Airy disk.


Apertures



Resulting Images


5.C TEMPLATE MATCHING USING CORRELATION


Correlation measures the degree of similarity between two functions. The correlation value peaks at points where there is an exact match.


For example to find the letter A in the text…




…we use the template



We then element per element multiplied the fft of the template and the conjugate of the fft of the text. The image of the inverse fft is



The text is now inverted but we can still check that the bright peaks occur at the locations of the letter A.



5.D EDGE DETECTION USING THE CONVOLUTION INTEGRAL


Another application would be edge detection. We can convolve an image with a matrix pattern of an edge using the function imcorrcoef in Scilab.


When the edge pattern is horizontal the horizontal edges are emphasized.



Likewise for a vertical edge pattern.



Spot pattern gives me the best result


I give myself a grade of 10 because I was able to do all that was required in this activity.