Unlike the last activity in which I had such a hard time, this was more lenient, because Fourier Transforms are easy to deal with. Given a certain image, the Fourier Transform of the image in matrix form can be used to obtain its image in spatial frequency domain. The equation of the Fourier Transform can be divided into real and imaginary parts given by:
Figure 1 |
So here Figure 1 shows an image of a circle with radius of 50% of total length of image or 64-bit radius. We take the Fourier transform and shift the image. Note we have to take the FFTshift or else the image will be just a dark figure. Figure 2 is the resulting image.
Figure 2 |
Next we take the Fourier Transform of the letter "A." (Figure 3) The resulting Fourier Transform of Figure 3 is Figure 4. Take the Fourier Transform of Figure 4 again which is essentially taking the inverse Fourier Transform of figure 3 and we come back to the original image.
Figure 4 |
Figure 5 |
Next we perform convolution of two images. Convolution of two images is essentially the product of element per element of the two images in matrix form in inverse spatial frequency domain. Here the Fourier Transform is performed on the image VIP. It is then multiplied to a circle with an aperture of different radius. Since we are dealing with 128 bits, the circle is forced to have 128 x 128 elements. The elements are then multiplied to the Fourier transformed image. Figure 6 shows the resulting images.
Figure 6 |
The resulting image becomes unidentifiable as the aperture becomes smaller and smaller. Next we perform correlation. In correlation before multiplying two images element per element, the conjugate of one of the images in matrix form is taken in its frequency domain. Here Figure 7' s matrix is applied the function conj().
before element per element multiplication of the letter A.
Figure 7 |
Figure 8 |
Edge Detection:
Another important application of Fourier Transform, is edge detection. By performing a convolution of 3 x 3 unit matrix and an image, the edges of the image can be seen. At points where there is no change, the matrix gives a value of zero. When the matrix does change, the value is no longer zero. The following matrices are convolved against the same VIP image. The more variation there are in the matrix, the better the edge detection.
Figure 9 |
where Gx and Gy are the matrix operators shown in Figure 10. As you can see the resulting image gradient: the Sobel Gradient shows a very sharp line on the edge of the letters VIP!
Figure 10 |
I would give myself a 12 for this activity!!!
Code Snippet:
//Set-up
x = [-1: 0.0157480:1];
[X,Y] = meshgrid(x);
r = sqrt(X.^2 + Y.^2);
circle = zeros(size(X,1), size(X,2));
circle(find (r <=0.05)) = 1.0;
//imshow(circle);
A = double(rgb2gray(imread('C:\Users\Phil\Desktop\A.png')));
//imshow(A);
VIP = double(rgb2gray(imread('C:\Users\Phil\Desktop\VIP.png')));
//imshow(VIP);
Spain = double(rgb2gray(imread('C:\Users\Phil\Desktop\CorrelationC.png')));
//imshow(Spain)
//FFT Circle
r = fftshift(fft2(circle));
//imwrite(mat2gray(abs(r)), 'FFTCircle.bmp');
//FFT twice
s = fft2(fft2(circle));
//imwrite(mat2gray(abs(s)), 'FFTtwice.bmp');
//FFT Letter A
z = fftshift(fft2(A));
//imwrite(mat2gray(log(abs(z))),'FFTA.bmp');
t = fft2(fft2(A));
//imwrite(mat2gray(log(abs(t))),'InverseFFT.bmp');
//Convolution
FFTVIP = fft2(VIP);
FFTCircle = fftshift(circle);
convolved = fft2(FFTVIP.*FFTCircle);
G = mat2gray(log(abs(convolved)));
//imwrite(G,'FFTConvolved0.05.bmp');
//Correlation
FFTA = fft2(A);
FFTSpain = fft2(Spain);
F = mat2gray(log(abs(fftshift(fft2(FFTA.*conj(FFTSpain))))));
//imwrite(F,"FFTCorrelation.bmp");
//Edge Detection
MAT = zeros(128,128);
MAT2 = zeros(128,128);
randomat = [-1,0,3;5,-2,-4;2,-1,-2];
submat = [-1,-1,-1;2,2,2;-1,-1,-1];
submat2 = [-2,1,-2;1,4,1;-2,1,-2];
submat3 = [0,1,0;1,-4,1;0,1,0];
submat4 = [3,-1,3;-1,-8,-1;3,-1,3];
submat5 = [-4,7,2;-8,-1,3;2,-2,1];
sobelx = [-1,0,1;-2,0,2;-1,0,1];
submat7 = [-0.25,0,0.25;0,0,0;0.25,0,-0.25];
sobely = [1,2,1;0,0,0;-1,-2,-1]
MAT([63 64 65], [63 64 65]) = sobely;
MAT2([63 64 65], [63 64 65]) = sobelx;
FFTVIP = fft2(VIP);
FFTMAT = fft2(MAT);
FFTMAT2 = fft2(MAT2);
convolvedmatrx = fftshift(fft2(FFTVIP.*FFTMAT));
convolvedmatrx2 =fftshift(fft2(FFTVIP.*FFTMAT2));
H = mat2gray(abs(convolvedmatrx));
I = mat2gray(abs(convolvedmatrx2));
J = sqrt((H.*H) + (I.*I))
imwrite(J,'sobel.bmp');
imwrite(edge(VIP,'sobel'),'sobel2.bmp')
References:
1. Soriano, Jing Activity 7 Activity 7: Fourier Transform Model of Image Formation
No comments:
Post a Comment