Archive for July 28, 2010

Properties of the 2D Fourier Transform

A. Familiarization with FT of different 2D patterns

The following images show the Fourier transform of some basic 2D patterns. For better symmetry, these patterns were generated in Scilab.

FT of a square aperture.

FT of an annulus.

FT of a square annulus.

FT of a double slit.

FT of two dots.

B. Anamorphic property of the Fourier Transform

We now investigate the Fourier Transforms of 2D sinusoids at different frequencies. The FT of the sine function, as depicted by the peaks in the image, is the Delta function. We can observe that these peaks move farther away from each other as the frequency is increased.

FT of a sinusoid with frequency of 1.
FT of a sinusoid with frequency of 4.
FT of a sinusoid with frequency of 10.
FT of a sinusoid with frequency of 20.

We can simulate a real image by adding a constant bias to the sinusoid. This bias is a DC signal with zero frequency. It causes the additional peak at the origin of the resulting FT, in between the peaks of the frequency of the sinusoid. Suppose we have an interferogram obtained from Young’s Double Slit experiment. The intensity of the interference pattern causes this DC term or zero order term formation. To find the actual frequencies of the interferogram, we can use a filter that removes the unwanted frequencies before applying FT.

Addition of bias at a sinusoid with a frequency of 4.

Rotating the sinusoid to a certain degree also rotates the peaks of its FT in the opposite direction.

FT of a sinusoid rotated 30 degrees.
FT of a sinusoid rotated 60 degrees.

Next we generate a pattern which is a product of two sinusoids (x and y direction).

FT of two combined sinusoids in the x and y direction.

We now add several rotated sinusoids to this pattern and calculate its FT. As I predicted, the final FT is just the superposition of the individual FTs of the functions used. This follows from the property of the FT as a linear transform.

FT of two combined sinusoids plus a sinusoid rotated 30 degrees.
FT of two combined sinusoids plus a sinusoid rotated 60 degrees.

I give myself a score of 10 since all the requirements were done correctly.


Fourier Transform Model of Image Formation

The Fourier Transform is an important image processing tool used to decompose an image into its sine and cosine components. [1] It transforms an image in the spatial domain into the frequency domain.

A. Familiarization with discrete FFT

The Discrete Fourier Transform is the sampled Fourier Transform. It does not contain all frequencies of an image but only a set of samples large enough to fully describe the spatial domain range. For this part, we explore the Fourier transforms in Scilab and apply them to two images created in Paint. The first image is a white circle on black background.

I = imread('circle.bmp'); //open image
Igray = im2gray(I); //convert to grayscale
FIgray = fft2(Igray); //2D FFT
scf(); imshow(abs(FIgray),[]); //intensity image
scf(); imshow(fftshift(abs(FIgray))), []); //shift image
scf(); imshow(abs(fft2(FIgray))); //FFT twice
xset("colormap", hotcolormap(40));

Figure 1. Fourier transform of a circle. (1) Original image (2) Intensity image (3) Shifted image (4) FFT twice.

The second image above shows the resulting FFT intensity image. Since the fft2 function rotates the quadrants of the image, we can observe the values at the corners of the image. Upon applying fftshift, the values are then adjusted to the center as shown in the third image. This is consistent with the analytical FT of a circle, which is a sinc function or an airy disk pattern. The last image shows the recovered original image upon application of the FT twice. Though not evident in the circle, this is actually an inverted version of the original image. We can observe this for an image of “A”.

Figure 2. Fourier transform of "A". (1) Original image (2) Intensity image (3) Shifted image (4) FFT twice.

B. Simulation of an imaging device

Convolution is used to model the linear regime of instruments or detection devices such as those used in imaging [2]. For this part we investigate the use of convolution in imaging systems. Consider an image of “VIP” as the object and an image of the circle as the lens aperture. We then observe the quality of the convolved image that corresponds to different aperture radii.

Figure 3. Object image.

r=imread('circle.bmp');
a=imread('VIP.bmp');
rgray = im2gray(r);
agray = im2gray(a);
Fr = fftshift(rgray);
Fa = fft2(agray);
FRA = Fr.*(Fa); //product of FFTs
IRA = fft2(FRA); //inverse FFT
FImage = abs(IRA); //convolved image
imshow(FImage, [ ]);

Figure 4. Aperture sizes and resulting convolved images.

Since the lens radius limits the number of rays reflected off the object, we can observe that smaller aperture size results to more blurred images than bigger aperture size.

C. Template Matching using correlation

Given two functions f and g, their correlation p which measures their degree of similarity is given by

p = f g.

Alternatively, the correlation that holds for their transforms can be expressed by

P = F * G.

Correlation can be used to find a certain object in an image. To demonstrate, we used an image of “THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN” and find all A’s in it.

rgray = gray_imread('SPAIN.bmp');
agray = gray_imread('A.bmp');
Fr = fft2(rgray);
Fa = fft2(agray);
FRA = Fa.*conj(Fr);
IRA = ifft(FRA); //inverse FFT
FImage = abs(IRA);
imshow(fftshift(abs(FImage)), []);

Figure 5. Template Matching using correlation.

Based on the resulting image, we can see that the correlation of the two images has the highest values in the locations of the A’s as depicted by the bright spots.

D. Edge detection using convolution integral

Edge detection is similar to template matching of an edge pattern with an image. Here, the VIP image was convolved with different edges matrices to detect its edges. These matrices were oriented in different directions and were of zero total sum.

h = [-1 -1 -1; 2 2 2; -1 -1 -1]; //horizontal pattern
v = [-1 2 -1; -1 2 -1; -1 2 -1]; //vertical pattern
s = [-1 -1 -1; -1 8 -1; -1 -1 -1]; //spot pattern
VIP = gray_imread('VIP.bmp');
image1 = imcorrcoef(VIP, pattern);
image2 = imcorrcoef(VIP, v);
image3 = imcorrcoef(VIP, s);
scf(); imshow(image1);
scf(); imshow(image2);
scf(); imshow(image3);

Figure 6. Edge detection.

We can see that the horizontal pattern detects only the horizontal edges clearly, whereas the vertical pattern detects only the vertical edges clearly. The spot pattern has the best edge detection since it was able to detect all the edges of the image.

References:

[1] http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm

[2] Soriano, M. Fourier Transform of Image Formation. 2010.

—————————————————————————————————————————————————

I give myself a score of 10 for this activity.



Design a site like this with WordPress.com
Get started