Wednesday, July 22, 2009

Activity 8: Morphological Operations

For this activity, we were able to explore different morphological operators and functions. Morphological operations were applied to five objects, namely: circle, square, hollow square, cross and triangle.

For the first part, the five images were eroded using four different structuring element. The first is a 4 X 4 ones, followed by 2 x 2 ones, 4 x 2 ones and lastly a cross that is 5 pixel long and a pixel thick.


SE = 4 x 4 ones

SE = 2 x 2 ones
SE = 4 x 2 onesSE = cross

The same objects were also dilated using the same structuring elements

SE = 4 x 4 ones

SE = 2 x 2 ones

SE = 4 x 2 onesSE = cross

As can be observed in the obtained dilated and eroded images, dilation pads-up the object depending on the dimensions of the structuring element used. On the contrary, erosion erodes the image as dictated by again the structuring element.

Before programming the erosion and dilation of the objects used, we were first asked to predict the results. Almost all of the predicted results for the dilation and erosion of images were the same as the results when programmed.

Other morphological operations like skel and thin were also explored.

The first column of the image above is the image original image, the second is the image after applying the function skel and lastly in the third column is the image after applying thin. The skel function skeletonizes the image. The thin function is also the same as the skel, however the method in which it thins the object is different to that of scale. As can be observed in the image above, the result of the skel is better than that of the thin function. Discontinuities are present in the thin function.

For this activity, I give myself a grade of 9 for I was able to do all the required tasks. However I was not able to fully discuss the process of morphology.

I thank Ms Herminia Balgos for discussing with me this activity.

Wednesday, July 15, 2009

Activity 7: Enhancement in the Frequency Domain

In this activity images are enhanced by filtering unwanted frequencies in the frequency domain.
For the first part of the activity, we were instructed to create symmetric dots and squares and obtain its Fourier transform. These were the images(left) and their corresponding Fourier transform(right) .


The Fourier transform of a point is a sinusoid. This is observed in the first pair of images where it can be seen that the image of the Fourier transform of the points looks like a mesh with varying intensity which is actually a sinusoid; and is only seen as that because the image is two dimensional.
On the other hand, the Fourier transform of two symmetric circles looks like an airy disk with a mesh inside. This is because the Fourier of the circles can be thought as the product of the Fourier transforms of two points and a circle. We know that the Fourier of a point is a sinusoid and that of a circle is an airy disk. Thus this resulted to the observed Fourier transform of the symmetric circles.
The same analogy applies for the square. The Fourier transform of the symmetric squares can be thought as the product of the Fouriers transforms of a square and two points. Again the Fourier of a point is a sinusoid and that of a square is a sinc. The product of the two will look like a sinc with a mesh of varying intensity inside. This is the observed Fourier transform of the symmteric squares.

It was also observed that as the radius of the circle and the sides of the square increases, the size of its corresponding Fourier transform decreases. This is the scaling property of the Fourier transform. Given a function, h = f(ax), its Fourier transfrom will be, H = (1/a)F(ax) [1].

Aside from circle and square, the Fourier transform of Gaussians were also observed for varying values of the variance.variance = 0.1variance = 0.4
variance = 0.8

Gaussian unlike other functions has a Fourier transform similar to a Gaussian. It is a self reciprocal function [2]. It can be observed that the obtained Fourier transforms looks like a gaussian with a mesh inside. The explanation for this is similar to what was discussed earlier. The Fourier transform of two symmetric gaussians can be thought as the product of the Fourier transfor of a gaussian and two points. Thus this will result to the image obtained.

Similar to what was observed earlier for the circle and square, increasing the variance of the gaussian results to the decrease in the size its Fourier transform. This is due to the scaling property of the Fourier transform.

After familiarizing ourselves with different Fourier transform, we then enhanced images by filtering unwanted frequencies in its Fourier transform. This was first done with the image of a fingerprint as shown below.Taking the Fourier transform of this image will result to the image below.

The Fourier transform of the image contains frequencies of the image. Blocking unwanted frequencies will result to an image absent of the unwanted details corresponding to the blocked frequencies. With this in mind a filter was created using gimp.

Multiplying this filter to the Fourier transform of the image will block unwanted frequencies and will result to the image below.

As can be observed, other details like the text "CO" and "09" and "INDEX" were omitted from the filtered image.

Using the same principle, the process was applied to another image below.

Its Fourier transform is the image below.

This is the masked used to block unwanted frequencies.

After getting the inverse Fourier of the product of the Fourier transform of the image and its mask..
As can be observed the lines present in the original image are not visible in the filtered image. Also notice the mask used to block the unwanted frequencies. It can be noticed that the mask looks like the Fourier transform of a sinusoid with different frequencies. This is because the lines present in the original image can be thought as sinusoids.

The same process was used for an oil painting in Vargas Museum. Since the oil painting was painted in a canvas, one can actually separate the painting itself from the canvas using frequency filtering. The painting is the picture below. The Fourier transform of the image is..


To create a filter mask removing the canvas weaves, we must first think what should the Fourier transform of the canvas weave look like. Based from the knowledge from the previous exercise we have an idea that the Fourier transform of the canvas will look like the Fourier transform of several sinusoids with different frequencies. Thus the filter will look like...
The resulting filtered image will then be...

As can be observed the brush strokes are more enhanced than the canvas weaves. Similarly, we can invert the filter used to mask the canvas weave so that we will be able to simulate the appearance of the canvas weave.


As can be observed, the simulated canvas weave thus looks like the canvas weave of the painting.

I would like to acknowledge Irene Crisologo for teaching me how to create a filter in Gimp.

for this activity I will give myself a grade of 10 for I was able to do and enjoy all the requirements for this activity.

References:

[1]http://en.wikipedia.org/wiki/Fourier_transform
[2]http://cnyack.homestead.com/files/afourtr/ftgauss.htm
[3]Activity 7: Enhancement in the Frequency Domain Manual

Wednesday, July 8, 2009

Activity 6. Properties of the 2D Fourier Transform

Disclaimer: partially done.

6.A Familiarization with FT of different 2D patterns

For this part of the activity the Fourier transform of the different patterns: square, square annulus, annulus (doughnut), Two slits along x-axis symmetric about the center and two dots along x-axis symmetric about the center were simulated.


Two-slits

square

two dots

square annulus

annulus(doughnut)

B Anamorphic property of the Fourier Transform

For this part of the activity a 2D sinusoid was generated. Similar to the previous part of the activity, its Fourier transform was calculated.The Fourier transform of a sinusoid is a dirac delta peaking at both positive and negative values of its frequency. The sinusoid generated is along the x axis with frequency equal to 4. Thus its resulting Fourier transform is an image peaking at two point (which I think is 4 and -4).

The Fourier transform of a sinusoid with a constant bias was also observed.bias = 0.1, frequency = 4


bias = 0.5, frequency = 4
bias = 2, frequency = 4

Adding a constant bias in the sinusoids results to a peak in the origin in the frequency space of the Fourier transformed image. As can be seen from the images above, the Fourier transform of the images for a sinusoid with frequency of 4 and bias equal to 0.1,0.5 and 2 have peaks at the origin. It can be noticed that at values much less than 1, the peak found at the origin has a lesser intensity compared to the peaks found at the value of the frequencies. And as the value of the bias increases (greater than 1), the intensity at the origin becomes greater than the value of the frequencies. This is because the range of values of sine is from -1 to 1 only. Hence, biases at this range does not exceed the peak of the frequency values. However, biases out of this range has a peak higher than the frequency values.

When the generated sinsusoids were rotated by a desired angle, the resulting Fourier transfrom were the following:
frequency = 4, angle = 0 degreesfrequency = 4, angle = 45 degrees

frequency = 9, angle = 90 degrees

When the sinusoid was rotated by an angle, the resulting Fourier transformed was also rotated by the same angle. The images abve shows sinusoids of frequency 4 and 9 with angle of rotation equal to 0, 45 and 90 degrees.

When the combination of two sinusoids was Fourier transformed, the resulting image is the following:
frequency = 4

The Fourier transform of the new sinusoid which is the product of two sinusoids (corrugated roof) running in the x and y direction shows the frequencies present in the product.

When several sinusoids are added to the previous sinusoid shown above the resulting image and its Fourier transfrom is found to be..


frequency = 4 at angles 30, 90, 120 and 330 and previously generated sinusoid

The Fourier transform of the image is the same as my predicted result. One property of Fourier transform is linearity. It means that given a function h which is expressed by f and g and its corresponding Fourier transform H, F and G, the Fourier of h is given by..

h = f + g
H = F + G

Because of this property of Fourier transform the image of the generated sinusoid above will just be sum of the Fourier of the previously generated sinusoid which is the corrugated roof, and the sinusoids with frequency equal to 4 rotated at angles 30, 90, 120 and 330 degrees.

I give myself a grade of 10 since Iwas able to do all the required tasks and I was able to observe and understand the properties of Fourier transform.


Monday, July 6, 2009

Activity 5: Fourier Transform Model of Image formation

A. Familiarization with discrete FFT

For this activity, we were able to demonstrate Fourier transform and convolution. The first exercise that we did was to get the Fourier transform of an image.


The first column in the images above are the original images of a circle and letter A. The second column on the other hand is the calculated shifted fast Fourier transform of the original images. These were computed using the function fft2 in Scilab. Lastly the last column are the resulting images after getting the fast Fourier transform of the images in the second column.

Analytically the Fourier transform of a circle is an airy disk. The image of the calculated Fourier transform of the circle looks similar to an airy disk.

Observe that the obtained Fourier transform of the first Fourier transform of the image is the inverted version of the original image.

B. Simulation of an imaging device.

Convolution is used in modeling the linear regime of instruments or detection devices such as those used in imaging [1]. For the next exercise, we demonstrated the use of convolution in imaging systems.

In imaging, given an object f and the transfer function g, the image produced by the imaging system is the convolution of of f and g. From the convolution theorem, we know that the Fourier of the convolution of two functions is equal to the the product of their respective Fourier transform. With this in mind, we used a circular aperture and the image "VIP" as the object. Multiplying the fft shift of the aperture and the fft of the image and lastly getting the inverse Fourier of the product will lead to the second column of the images below.

The images above shows the image of the aperture and the corresponding resulting image. It can be observed that as the aperture size decreases, the image of the object becomes more blurred. This is expected since when the aperture is small less amount of light will be able to enter the system; thus resulting to a blurred image. Again it can be observed that the resulting image is inverted. This is because of it resulted from the inverse Fourier. The same reason for the inverted images in the first part of the activity.

C. Template Matching using correlation

Correlation measures the degree of similarity between two functions. [1] Similar to the convolution theorem the Fourier of the correlation P is equal to the product of two Fourier transformed functions, F* and G where * stands for complex conjugation.

P = F*G

For this part of the activity we used an image containing the text, "THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN" as the function F and the previously used image of "A" as the function G. The inverse Fourier P is the image below.

The image of the correlation as can be seen above is blurred for the same reason as the other two previous part of exercise. However notice that all the letters A in the resulting image does not look like A but looks like a bright spot. This is expected since the function g used is the image "A". Correlation measures the degree of similarity. In this case, all the letter A in the text in function F contain a high correlation value resulting to the bright spot for all locations of A.

D. Edge detection using the convolution integral

For this part of the activity, 3 matrices where used in order to perform edge detection. Each matrix used has a total sum of zero. Edge detection was done by convolving the matrix unse with the image "VIP".As can be seen in the images above, the image "VIP" became more clear at directions same as the direction of similar values in the matrix. For example in the first image, the matrix used has same values in the vertical direction and because of this the resulted image has a clearer vertical spots. This is because this parts of the image are the ones detected as dictated by the used matrix.

For this activity I'm giving myself a grade of 10 for I was able to do the exercise right.

I thank Ms Herminia Balgos for making the "VIP" image for me.