Tuesday, July 12, 2011

VI

Activity 6 formally introduces us to the Fourier Transform model of imaging.
 (1)

Eq. 1 is the 2D Fourier transform of a function f(x,y). For image processing implementations in this activity, we will be using Cooley and Tukey's Fast Fourier Transform algorithm. Before I discuss the results, I'd like to note the importance of some Scilab functions to achieve the proper results.

  • gray_imread() : As we can see, we can't have a multi-channeled image (hypermatrix). This function basically flattens our subject matrix, else fft2() won't work properly.
  • abs() : Let us not forget that employing a FT generates a complex function. This is thus necessary in appropriately projecting our results as an image (matrix of real values).
  • fftshift() : This allows us to flip a matrix along its diagonal. Useful, since fft2() has its quadrants interchanged along the diagonal.
6A. Discrete Fourier Transform

Figure 1. Left to Right: Original image, fft2() result, fftshift() result and the twice fft2()'d image.

Fig. 1 shows the result of a series of FTs on an image of a circle (r=0.9 with respect to 128). The fft2() resulted an almost black image with some white-ish pixels uniformly distributed on its vertices. Upon inspection of the numerical results, most of the values are well beyond 100, and thus appeared as black pixels. Applying fftshift() creates a speckled pattern of black pixels on a white background. This function apparently has an effect to the numerical values of the FFT. The right-most image shows that Fourier Transforms are transitive, that is, employing it 2 times results to the original function.


Figure 2. Left to Right: Original "A" image, fft2() result, fftshift() result and the twice fft2()'d image.

Fig. 2 shows the result of an "A" image that underwent the same processes as that in Fig. 1. It is noticeable that the frequency distribution (3rd image from the left) also has the same triangular features as that of the original image spread radially, possible remnants of the 2D nature of the FT used. The final image is a good example of how fftshift() corrects the orientation of the transformed image.

6B. Convolution






Figure 3. Convoluted images of "VIP" and a simulated aperture of various radii. Top to Bottom: r=0.3, 0.4, 0.5, 0.6, 0.7, 0.8 and 0.9

Fig. 3 successfully shows that the convolution is indeed effective in simulating an object-lens relationship. As the aperture is reduced in size, diffraction artifacts became more and more noticeable. These are the result of "smearing" brought by the convolution of the 2 image matrices. Let's investigate the mathematical description for Convolution:
 (2)

The difference in the g function ultimately generates the "smearing" that we observe.

6C. Template Matching using Correlation


Figure 4. Top: L-R Image and pattern filter, "A". Bottom: L-R Output image of correlation, rotated image (180 deg. counter-clockwise)

Fig. 4 exemplifies the capabilities of template matching using correlation. White dots on the bottom-right are visible to all the "A" in our base image. Let us note that the Correlation is given by:
 (3)
The sum in the g function enables proper detection of similar patterns for 2 image matrices. The function conj() is essential to have the inverse signs for the elements of our initial matrix to facilitate with Eq. 3.

6D. Edge detection using the convolution integral

Finally, we examine the capabilities of convolution for identifying patterns, such as linear ones for edge detection.


 
Fig. 5 Results of imcorrcoef(). Patterns used from L-R:  [-1 -1 -1; 2 2 2; -1 -1 -1], 
[-1 2 -1; -1 2 -1-1 2 -1] and  [-1 -1 -1; -1 8 -1; -1 -1 -1]

The first image shows our image with most of its vertical lines lost. The second one is visibly without its horizontal lines. The third image that used a spot pattern has its vertical and horizontal lines intact, indicating that the algorithm "identifies" closed loops.


This activity has really improved my knowledge on FT and its applications for visual analysis and pattern recognition.

Self-Assessment: 10/10 

No comments:

Post a Comment