We’ve done a lot on image processing; we’ve learned a lot of ways to determine the properties and information about images. Here we would be discussing another way- getting the Fourier domain of the image. Fourier transform is a process of converting signals from a dimension X to dimension of 1/X. For images, this converts the spatial domain of images to the frequency domain. A fast way of implementing FT is through the Fast Fourier Transform algorithm. [1,2] For our fourth activity, the concept of Fourier transform was used for image processing.
Familiarizing with discrete Fourier transform
Fourier transform can be performed in images using Scilab. First, we were asked to get the FFT of different synthetic images with dimension of 128 x 128 pixels. FFT for 2D signals makes use of the function fft2(). The dimension was chosen as such because fft2() was more efficient for images with sizes in power of two. [2] We have learned to use Scilab in make synthetic image of circle. Circles of different radius were produced and FFT would be applied to each.
Synthetic images of circles with different radius sizes. |
Basically, applying FFT in images using Scilab is as follows. Since synthetic images produced from Scilab was purely single channel, no need to read the image in grayscale. Some alterations on the given sample code was made like using the double() function to convert the image matrix values into floats before applying the fft2(). The output of the the fft2() are complex number array so abs() function was used to compute the magnitude of the complex number. Function mat2gray() was also used to represent the matrix as grayscale image. Finally, image was show using either the functions imshow() or imwrite().
The FFT of the circles resulted like a diffraction pattern when light was made pass through slits: as the radius of the circle was decreased, the pattern became more prominent (fringes became bigger). The output of the FFT below was observed on the corner. Thus the FFT must be shifted to move the information to the center of the image.
FFT of circles with different radius. |
Function fftshift() was used and this results to the output below.
Shifted FFT of circles of different radius. |
A sample Scilab code employing FFT on image is illustrated below
FFT was also applied to letter A with font style Arial and font size of 50 pt. The inverse Fourier transform is the conversion of images from the frequency domain to the spatial domain. This can be done just by using the forward FFT however the image produced is inverted. [2] Applying inverse FFT to the FFT of circle, the output observed just looks its original image. When it was applied to the FFT of letter 'A' image, it resulted to an inverted 'A'.
FFT was also applied to letter A with font style Arial and font size of 50 pt. The inverse Fourier transform is the conversion of images from the frequency domain to the spatial domain. This can be done just by using the forward FFT however the image produced is inverted. [2] Applying inverse FFT to the FFT of circle, the output observed just looks its original image. When it was applied to the FFT of letter 'A' image, it resulted to an inverted 'A'.
From left to right, synthetic image of letter A, FFT of 'A' image, shifted FFT of 'A' image, inverse FFT of the FFT of 'A'. |
Convolution: Simulation of an imaging device
Convolution is a linear operation that "smears" one function to another. The output function will look like the both the two input functions. This can also be applied to images. A synthetic image of the VIP text shown below was convolved to circles of different radius.
Synthetic image of the 'VIP' text. |
The resulting images were as follows. For this case, the circles were treated as apertures. For small apertures, the image output is blurry. As the aperture gets bigger, the image became clearer.
Convolution outputs using circles of different radius (refer to first figure for corresponding circle sizes) |
Correlation: Template matching
Another linear operation is the correlation. Correlation measures the similarity between the two functions. If there is high resemblance between the two functions, the correlation value is also high. This was done for the first two images below. Correlation was done in Scilab using the following steps. First, getting both the FFT of the letter A image and the complex conjugate of the FFT of the text image. Then multiplying them element by element. Dot product was only applied here. Function conj() was used to compute the complex conjugate. The resulting image is the last image below, which observed to have the brightest spot on the positions of the letter A in the text. This is just what expected since you want to see the correlation between the two images, that is having the letter A.
From left to right, image of the text, image of letter 'A' and the correlation output. |
Edge detection using convolution integral
Edge detection can be done using convolution. The edge to be detected was that from the text VIP while the detector was different 3x3 matrix pattern. For example, as how it should look like in the Scilab code,
pattern = [-1 -1 -1; 2 2 2; -1 -1 -1]
is the pattern for horizontal edge detector. The edge patterns and the corresponding detected edges were shown below. Explaining the result simply, the detected edge depended on the pattern used as aperture. Horizontal edges appeared brighter when horizontal edge pattern was used, etc. The whole edge was detected when the spot pattern was used.
Edge detection from left to right: horizontal, vertical, diagonal down, diagonal up, and spot size.
|
More code for this activity. I am really slow when it comes to coding so I am very grateful that this activity seemed like a class activity on the day this was sent to us. I thank Anjali Tarun, Alix Santos and Joshua Beringuela for the useful exchange of ideas especially the needed alteration for the code to work :) As usual I thank my blog/code buddy, Nestor Bareza.
A grade of 10/10 for me in this activity because I am able to do all the tasks..
__________
References
[1] R. Fisher, et al. Fourier transform. Retrieved from http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm
[2] Soriano, M. "Fourier Transform Model of Image Formation." AP 186 Laboratory Manual. National Institute of Physics, University of the Philippines, Diliman. 2013.