Monday, July 7, 2008

Fourier Transform Model of Image



Part A: Fourier Transform of an Image

The
Fourier Transform (FT) is one among the many classes of linear transforms that recast information into another set of linear basis. In particular, FT converts a signal with dimension X into a signal with dimension 1/X. If the signal has dimensions of space, a Fourier Transform of the signal will be inverse space or spatial frequency. The FT of an image f(x,y) is given by:
F ( f x , f y )=∫∫ f ( x , y) exp(−i 2pi( f x x f y y )) dx dy
This part of the activity discusses mainly on getting the fourier transform of the image and returning to its original image (meaning getting the fourier transform twice) . Getting the fourier transform twice will give an inverted original image. The simple source code is written below (at the appendix).
Figure 1. Fourier transform of 2d(image)
Part B: Convolution

The convolution between two 2-dimensional functions f and g is given by
h  x , y =∫∫ f  x ' , y '  g  x – x ' , y – y ' dx ' dy' .
or simply h = f*g.
The convolution is a linear operation which means that if f and g are recast by linear transformations, such as the Laplace or Fourier transform, they obey the convolution theorem:
H=FG
where H , F and G are the transforms of h, f and g, respectively. The convolution is a “smearing” of one function against another such that the resulting function h looks a little like both f and g.
In this part of the activity, a circular image with different sizes were convolved to an image (VIP). As I decrease the size of the circular aperture, the resulting image after getting the convolution blurs more. Meaning, the smaller the diameter of the circle, the less the resolution of the resulting image.
Figure 2. Convolution of image to a circular image

Part C: Template Matching by Correlation

The correlation p measures the degree of similarity between two functions f and g.
The more identical they are at a certain position x,y, the higher their correlation
value. Therefore, the correlation function is used mostly in template matching or
pattern recognition.
For this part of the activity, I made an image with written words,"THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN". I also made an image template written,"A" with the same font size as of the phrase. The two image has exactly the same size. After getting their correlation and returning the original image by fourier transform, the resulting image highlights all A's.

Figure 3. Matching the template to the original image
Part D: Edge detection

In this part of the activity, correlation was utilized (same as Part C) but the template used here are different nxn matrices wherein the total sum of the matrix is equal to zero. The convolved images for different patterns of matrices detect the edge of the image and the direction of the edges depends mainly on the pattern of the matrix. For example, for the first matrix (Pattern 1), all same values in the matrix are in the horizontal direction. The edge of the resulting image also in the horizontal direction. But for the third pattern, the direction of the numbers with the same values are both in the horizontal and vertical direction thus forming edges both vertical and horizontal (including the diagonal direction).

Figure 4. Matrix pattern for the edges and the resulting image after convolutiion


For this activity, I proudly dive myself a grade of 10 because I got all my results properly.

Collaborator:
Billy Narag

Appendix:
Source Codes:
2D Fourier Transform;

a = imread("C:\Documents and Settings\AP186user15\Desktop\A.bmp");//File open
b = im2gray(a);//set to grayscale
Fb = fft2(b);//Fast Fourier Transform
Fb2 = (abs(fft2(fft2(a))));//Twice Fourier Transform
scf(1)
imshow(abs(Fb),[]);
scf(2)
imshow(fftshift(abs(Fb)),[]);
scf(3)
imshow(Fb2,[]);

Convolution;

a = imread("C:\Documents and Settings\AP186user15\Desktop\circle.bmp"); //open file
c = imread("C:\Documents and Settings\AP186user15\Desktop\VIP.bmp"); // open file
b = im2gray(a); // converts image to grayscale
d = im2gray(c); // converts image to grayscale
Fshifta = fftshift(b); // Shift the FFT
Fc = (fft2(a));//Fourier Transform of the image
FCA = Fc.*(Fshifta);// Convolution
InFFT = fft2(FCA);//Fourier transforming the image back
Fimage = abs(InFFT); // getting the absolute value
imshow(Fimage,[]);


Correlation;

a = imread("E:\AP 186\Activity 6\A2.bmp");//open image file
c = imread("E:\AP 186\Activity 6\The rain.bmp");/
/open image file
b = im2gray(a);// converts the image file into grayscale
d = im2gray(c);//
Fa = fft2(b);// fast fourier transform
Fc = fft2(d);
Fc_conj = conj(Fc); // getting the complex conjugate
FCA = Fa.*(Fc_conj);//convolution
InFFT = fft2(FCA);
Fimage = abs(fftshift(InFFT));
imshow(Fimage,[]);


Edge Detection;

a = imread("C:\Documents and Settings\AP186user15\Desktop\Activity 6\VIP.bmp");//open image file
pattern = [-1 -1 -1; -1 8 -1; -1 -1 -1,];//matrix pattern
b = im2gray(a);//converts the image into grayscale
c = imcorrcoef(b,pattern);//convolution of the two matrices with different sizes
imshow(c,[]);


Source:

[1]Activity manual provided by Dr. Jing Soriano






No comments: