Martes, Hulyo 12, 2011

Activity 6 - Fourier Transform Model of Image Formation



      Fourier transform is a mathematical method where you convert information from a certain dimension to another. It is a linear transform where a signal in dimension x is converted to a signal in dimension 1/x. There are a lot of ways to implement a Fourier transform. One of the known way is the Fast Fourier Transform by Cooley and Tukey. There are function in Scilab that does it: fft() for a 1-D signal and fft2 for 2D-signal.

In this activity we would demonstrate Fourier transform on images. First we make a 128X128 image of a circle with a black background. Figure 2 shows the Image after performing the Fast Fourier Transform(FFT). Notice that the white parts on the side?
  
Figure 1. A circle generated using Paint
Figure 2. The circle after Fourier Fast Transform



This happens because once you perform a FFT, the quadrants are inversed. For better illustration; look at Figure 3. The code used for the FFT is shown in Figure 4.

Figure 3. The original image(left) and the image after FFT where the quadrants are inversed. 


Figure 4. The code used for using FFT on the image.

We can shift the quadrant back to its proper place by using the command 
imshow(fftshift(abs(FIgray))), []); which was used in the code in Figure 6. 
Figure 5. Image after shifting the quadrants of figure 2 to its proper place
Figure 6. Code used for putting the quadrants back to its proper place.

Now we can inverse the transform we used by using another FFT. 
imshow(abs(fft2(fft2(Igray))));
Figure 7.The image after using another FFT on figure 5.

Looking at Figure 7; it may look like the original circle but it is already inverse of the original. image. We can see it more clearly by doing the same things done on the circle to the image with the letter 'A'.




Figure 8. Image of letter 'A' generated using Paint
Figure 9. The letter 'A' after Fourier Fast Transform
Figure 10. Image after shifting the quadrants of figure 9 to its proper place 
Figure 11. The image after using another FFT on figure 10
We can see more clearly on Figure 11; that the original image is inverted after using another FFT on the image.

On the next part of the activity we investigate the concept of convolution.


Convolution Method
Convolution is like smearing two functions such that the resulting image looks a bit like each of the individual function. The convolution of two 2D function f and g is given by the integral:

Simulation of an imaging device Convolution Method

First we simulate an imaging device by varying its 'aperture' and convolving it with the VIP image. The circle here would be our aperture and we would multiply it to the VIP image. The circle here would serve as the aperture of the lens used in the camera. We know that the quality of photos taken by a camera is dependent on the aperture of the lens. The Simulation was done by using the code in figure 14. Notice that when you increase the aperture, the quality of the image improves. We can also observe that when the aperture becomes so small, the quality of the image greatly deteriorates.

Figure 12. VIP letters generated  using Paint
Figure 13. The first 'aperture' of the lens
Figure 14. The code used for 'combining' the aperture and the VIP image.

Figure 15. The resulting image of the first aperture and the VIP image.

Figure 16. The second aperture with  a smaller radius
Figure 17. The resulting image of the small aperture(second) and the VIP image
Figure 18. The third aperture with a larger radius.
Figure 19. The resulting image of the  big aperture(third) and the VIP image.
Figure 20. The fourth aperture with a very small aperture
Figure 21. The resulting image of the very small aperture (fourth) and the VIP image.
Template Matching using correlation


Correlation


Correlation measures the degree of similarity of two function or images. The correlation of two 2D function is given by the integral:

In this part of the activity, we observe the method of correlation. To do this we made an image containing a text message and correlate it to a single letter('A") that is contained in it. We multiply the FT of the text message and the single letter 'A'. After doing this we perform an inverse Fourier Transform on the product of the two images. Looking at the first correlation; we can observe that the image(figure 23) has high correlation but the image is blurred because the difference of the size of character is big. As the difference in the character size decreases; the image becomes sharper(Figure 27). This is because the correlation increases thus giving higher values.



Figure 21. A text image generated using Paint.
Figure 22. Image of letter 'A' generated using Paint

Figure 23. Correlation of the images in figure 21 and 22
Figure 24. Image of letter A with a medium-size font generated using Paint
Figure 25. Correlation of the images in figure 21 and 24
Figure 26. Image of letter A with a small-size font generated using Paint
Figure 27. Correlation of the images in figure 21 and 26
Edge detection using the convolution integral


Edge detection can also be considered a template matching technique. to show this, we convolve figure 12 with the pattern at figure 28. The code used for this part is seen on figure 7. The pattern that was used are horizontal,vertical,diagonal and spot patterns.The edges of V was seen more than the I and P at the diagonal pattern. The edges of I was more pronounced than V and P on the vertical pattern. It can be seen that the best edge detection was on the spot pattern. This is because the pattern s more similar for the spot pattern and VIP image.
Figure 28. Horizontal pattern generated using MATLAB
Figure 29. Result of edge detection by using a horizontal pattern


Figure 30. Vertical pattern generated using Scilab

Figure 31. Result of edge detection by using a vertical pattern
Figure 32. Diagonal pattern generated using Scilab
Figure 33. Result of edge detection by using a diagonal pattern
Figure 34. Spot pattern generated using Scilab
Figure 35. Result of edge detection by using a spot pattern

Figure 36. Code used for edge detection.



I would give myself a grade of 9/10 for finishing this activity.
References
[1]Soriano, 2011. Fourier Transform Model of Image Formation. Applied Physics 186.
[2] Wikipedia, 2011. Fourier Analysis.



Walang komento:

Mag-post ng isang Komento