To further explain the different characteristics of the Fourier transform that is very useful to image processing, this activity is divided into four parts.
7.A Familiarization with discrete FFT
The first part of the activity is a simple demonstration of the Fourier transform. We are tasked to create a 128 x 128 image with a small circle in the center. This was done using paint. Then the following code is implemented to obtain the Fourier transform of the image.
//Activity 7 Fourier Transform
I = imread('C:\Users\GreyFOX\Desktop\Acitivity 7\circle3.png');
Igray = rgb2gray(I);
Igray2 = double(Igray);
//imshow(Igray2)
FIgray = fft2(Igray2); //remember, FIgray is complex
imshow(abs(FIgray));
//
//FFT shift
image = mat2gray(fftshift(abs(FIgray)));
imshow(image)
imwrite(image,'C:\Users\GreyFOX\Desktop\Acitivity 7\fftimg3.png')
One may notice that after the Fourier transform function, I had to use another related function which is the fftshift to obtain the following image.
Figure 1. Fourier transform of a prepared 128x 128 image of a circle using paint.
The fftshift is necessary so that the zero frequency is on the center of the image. Also based from the discussion, the output of fft2() has quadrants along the diagonals interchanged.The fftshift() function interchanges the quadrants back.[1] The resulting image Figure 1 (right) is known as an airy pattern.
The codes are also applied to another prepared image of a letter "A" on a black background. As a result,
Figure 2. Fourier transform of a prepared 128 x 128 image of letter A
The result showed a figure that is symmetric both along the x and y axis. I dont know how to describe it but it somehow 'airy'. Another relevant concept to know is if you can RETRIEVE the original image from a Fourier transform image.
Figure 3. (left) image after using fft() again (right) after using ifft()
To correctly retrieve the image from a Fourier transform, one must implement an inverse Fourier transform, doing so can retrieve the original image figure 3(b), on the other hand, doing fft() again to the Fourier transform image will result to an inverted image in figure 3(a).
The image of letter the circle in figure 1. and the image of "A" in figure 2 is both constructed using paint. So we don't know the exact sizes of these objects. So to try and find out if the size of an object affects the results, i tried it to smaller and larger radius.
Figure 4. Fourier transform with varying initial size of circle
Given a bigger object its corresponding fft image is much smaller than the smaller circle. One can say that with the smaller circle, the airy pattern is more evident compared to the bigger one.
With the convolution property of the Fourier transform, one can simulate an imaging device, specifically in this activity, a simple circular aperture.
Figure 5. Image used for simulating the aperture
On the handout, the VIP image was dictated to be more than 50% of the area of the image. I tried to use smaller font size, and I found out that the larger images will just produce more observable than the smaller ones. The following results are done using Figure 5. The algorithm is just based on the manual, which utilizes the convolution property of the FT.
1) Get the product of the FT of both images (the aperture need not be FFT'ed) [1]
2) Get the inverse to get the convolved image.
Figure 6. 'Imaged VIP' using the aperture (circle) of varying radius.
The results shows that with larger aperture, it produces a very clear image compared to the smaller aperture. With the smallest aperture, i think that it is unidentifiable. This is consistent with natural phenomenon, since smaller aperture allows lesser light to pass or minimal light to pass, it will more likely result to a blurry image compared with bigger sized aperture.
In contrast with convolution, correlation can be described as the element per element product of the conjugate of the FT of first image and FT of another. Their difference is that convolution is the element by element product of both FT's of two images(without conjugating the one image). Its application will be presented by the following results
Figure 7. 128 x 128 image of two images to be correlated.
As you can see, "A" image will be correlated to the an image text composed of different letters. The correlation measures the degree of similarity between two images.[1]
Figure 8. Correlated images using figure 7.
In Figure 8, it is evident that there are bright white spots on different parts of the image. If you would closely, to the original text, and this result, you can notice that the bright spots were the place where the letter "A"s are located. Meaning at this point, there occurs a higher correlation value between the two images.In this note, it is reasonable that this correlation function are used in template matching and pattern recognition[1]
7.D Edge Detection
The last part of these activity is edge detection. Similar to the previous part, the method will be just template matching of an edge pattern with an image.
Given the following patterns as implemented in the scilab code (and given by the manual).
h_pattern = [-1 -1 -1; 2 2 2; -1 -1 -1]; //horizontal
v_pattern = [-1 2 -1; -1 2 -1; -1 2 -1];//vertical
diag_pattern = [2 -1 -1; -1 2 -1; -1 -1 2];//diagonal
spot_pattern= [-1 -1 -1; -1 8 -1; -1 -1 -1];//spot
jazz = imread('C:\Users\GreyFOX\Desktop\Jazz.png');
jazz2 = double(rgb2gray(jazz));
Edge1 = conv2(jazzgray, pattern_h); \\ varying pattern
imshow(Edge1);
imwrite('C:\Users\GreyFOX\Desktop\horizontal.png');
Figure 9. Original image to be detected.
Figure 10. Edge detection using different patterns (a) vertical (b) horizontal (c) spot (d) diagonal
The results showed a very nice implementation of edge detection. As you can see, with my name, it is better to use the spot pattern, since the letters have a lot of variation with edge patterns. Obviously, like the previous part, the (a)vertical pattern will detect vertical lines of the letters, and similarly with (b) horizontal pattern for horizontal lines, and so on.
-------------------------
When I finished the activity, i felt that it was so simple, but I was really stucked in this activity, especially on the first parts. It was really frustrating having minor mistakes like not having the absolute value(abs), or having errors which took me time to understand (because i am new to scilab).
For my self-grade, i would like to give myself a 10/10 for having produced the required output (though it took me a lot of time). I only enjoyed the last part where it demonstrates a nice way on finding the edge; unlike in Activity 5, where we only utilize the built-in function edge(). Maybe that's why i did not explore much on this activity.
Actually i tried changing the values of the edging pattern, with sum not = 0, unlike what it was said in the handout. The edge detection still works even the sum of the pattern is not 0. Only it would result to a weird pattern and it would recognize weird edges.
References:
[1]Maricor Soriano. AP 186 Activity Manual A7 – Fourier Transform Model of Image Formation.2013
No comments:
Post a Comment