Monday, July 7, 2008

..on fourier transform model of image formation

The Fourier Transform (FT) of an image is given by:



Below are 128x128 bitmap images of circles with different radius and letter A's in varying size.

























We apply discrete 2D FFT on these images. The output of the FFT is a complex number. Getting the modulus gives us the intensity.





Big Circle












Big A












Medium Circle













Medium A












Small Circle












Small A







Applying fftshift() gives us:






Big Circle












Big A












Medium Circle












Medium A













Small Circle












Small A







These images are consistent with the analytical FT of the circle. As the radius of the circle decreases, we clearly observe the airy disc. The same for the letter A. As the size decreases, the airy patterns becomes more distinguishable. Applying FFT twice on the image results to the original image, but as we notice for letter A, the resulting images are inverted.














































































Convolution

The convolution of two 2D function f and g is given by:



This could be represented as h=f*g. If F and G are the FT of f and g, respectively, then the convolution is just simply H=FG. Below are the convolution images between the word VIP and the circles of varying radius. The circle serves as the aperture. As the radius of the circle decreases, the aperture becomes smaller and the resulting image is blurred. The bigger the aperture, the sharper the image.











Aperture 1









Image 1









Aperture 2









Image 2









Aperture 3









Image 3







Correlation


The correlation of two 2D function f and g is given by:



This could be represented as p=fog. If F and G are the FT of f and g, respectively, then the correlation is just simply P=F.G. The correlation measures the similarity between the two functions. Some of its application are as follows:

Template Matching

Below are the correlation images between the sentence "THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN", and the letter "A" and the word "IN". We notice that the maximum in the resulting images occurs on the part of the sentence (image) where there is a presence of A or a form like A. Same is true for the word IN.























A











IN







Edge Detection

Below are images resulting from the convolution of VIP and a 3x3 matrix pattern of an edge such that the total sum is zero. The first is a horizontal, the second is a vertical, and the third is a spot pattern. Notice that for the first pattern, the horizontal edges of the image are highlighted. For the second pattern, it is the vertical edges that are highlighted. And for the spot pattern, all the edges are highlighted.





Horizontal Pattern











Vertical Pattern











Spot Pattern







I was able to finish the activity with the results consistent with what were expected. I think I deserve a 10.

Wednesday, July 2, 2008

..on physical measurements from discrete fourier transforms

The discrete fourier transform (DFT) is given by:





DFT could be used on getting the fourier transform (FT) of measured signal, numerically validating an analytic computation, and obtaining numerical results for signals whose FT have difficult or no analytic form.

To illustrate how DFT works, we first generate a sinusoidal signal (sin2pi()ft). Below is the plot of the generated signal with f=5 (frequency), T=2 (total signal time), N=256 (number of samples), and the sampling interval (dt) is given by dt=T/N.














We get the fourier transform of the signal. To get the frequency scale, we note that by Nyquist Theorem, the maximum frequency detectable is given by Fmax=1/(2dt). Since half of the output of the FT is just the mirror image of the other half, we just simply shift the half axis, and df=2Fmax/N. The resulting plot is:














The plot peaks at f=5/-5. This is consistent since the frequency of the generated signal is 5. The DFT could also be applied for images. Instead of a temporal signal (temporal domain), we have a spatial signal (spatial domain). The number of frequencies resulting from DFT represents the number of pixels on the original image. The method utilizes the 2 dimensional DFT given by:






The value of each point of X is obtained by multiplying the spatial image with the corresponding base function and summing the result. The base functions are sine and cosine with increasing frequencies. The resulting fourier transform is a complex valued number real and imaginary which represent the magnitude and the phase.
(source: http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm)

For a fluorescent lamp that flickers around 120Hz, the threshold sampling rate is given by dt=1/(2F). This is around 0.004167 sec. Below is the resulting DFT generated with f=120. In order to have a dt that is below the sampling threshold, N is set to 500 with T=2. We see that peak occurred at around 120. For comparison, we set N=400 with T=2 and we could observe that DFT failed to detect it correctly (peak at 80).




F=120
N=500
T=2
Detected F=120










F=120
N=400
T=2
Detected F=80






Increasing the number of samples (N) increases the frequency range detectable. If the original N results to a sampling interval greater than the threshold indicated by the Nyquist Theorem, increasing N would increase the accuracy of the detected frequency. Below are the plots with increasing N (15,100,256). We see that the results are consistent with the analysis.




F=5
N=15
Detected F=2.3
Max F=4










F=5
N=100
Detected F=5
Max F=25










F=5
N=256
Detected F=5
Max F=80






As indicated by the Nyquist Theorem, decreasing the sampling interval (dt) increases the maximum frequency that could be detected by the FT. This widens the frequency range that could be detected which is appropriate for signals that contain higher frequencies. Below are plots of decreasing dt. We decreased dt by increasing N (since dt=T/N).





dt=.02
Max F=25












dt=.005
Max F=100







Since dt x N=T, increasing N with T fixed decreases dt. This results to a smaller sampling interval and thus, increasing its detection range to higher frequencies without aliasing. Below are plots of increasing N. We could see that the maximum F increases.





N=256
Max F=80












N=400
Max F=80







The analysis above are consistent with the results of the simulations. I want to give myself a 10.