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.

Tuesday, June 30, 2009

Activity 4: Enhancement by Histogram Manipulation

In this activity we were able to enhance images through histogram manipulation. The steps in doing this are as as follows:

1. The normalized histogram of the image is determined. This was done with the help of the find command in Scilab.
2. From the obtained counts per grayscale value, the cumulative distribution probability (CDF) of the image is also determined.
3. A desired CDF is plotted. This is user-defined but for the purpose of this activity linear and logarithmic CDF were used.
4. Pixel per pixel, the grayscale values of the image are replaced by the corresponding grayscale value of the desired CDF with y values equal to the y values of the image's CDF. This is illustrated by figure 1.


This is the original image that was enhanced.

www.crestock.com/uploads/blog/b%26w-tutorial/street-havana-grayscale.jpg

Image Histogram

From the obtained image histogram, it was seen that the minimum grayscale value is 5 while the maximum is 255.
CDF

The figure shows the obtained normalized CDF. As can be observed from the figure the CDF is increasing. However it's increase is not linear.

The image above shows the desired CDF which is a linear plot ranging from 0 to 1. Using this desired CDF, backprojection is implemented and resulted to the enhanced image.The histogram and CDF of this enhanced image is as follows. Applying histogram equalization resulted to a more contrast image. It can be observed when the histogram of the enhanced image is compared to that of the original that the histogram of the enhanced is a strecthed version of the original. As can be seen the length of the grayscale values where peaks occured widened. This is in accordance to the desired CDF. In addition, it can be observed that the calculated CDF for the enhanced image follows the plot of the desired CDF. This is expected since backprojection is a pixel per pixel mapping of CDFs.

This same process were applied to the image below.


original image
http://gallery.photo.net/photo/5476781-md.jpgenhanced image

The shown enhancements are for linear CDF. The human eye however has a non-linear response and is similar to a logarithmic plot. Using logarithmic plot as the desired CDF resulted to the following enhanced images.As can be seen the enhanced images of a desired logarithmic CDF became darker as compared to that of the original.

For this activity I give myself a grade of 9 for I was able to enhance the images through histogram manipulation.

I thank Cherry Palomero, Irene Crisologo and Jaziel Vitug for discussing the activity with me.













Wednesday, June 24, 2009

Activity 2: Area estimation for Images with defined edges

For this activity the area of binary images are estimated. This was done using Green's theorem that relates a double integral to a line integral. This is given by the following equation;

Using this equation it can be found that the area of an enclosed region is given by the following equation in discrete form;
Using this formula, the area of various generated shapes were estimated using scilab 4.1.2 with a SIP toolbox. Here are the shapes whose areas where estimated.

square

circle

triangle

The estimated and analytical values of the areas are shown in the following table. The analytical value of the area for each shape is calculated using pixel counting.
The errors in the estimated area came from the offset in the detected contour of the follow command in scilab. The 'true' contours of some corners of the shape were not detected accurately. Hence it resulted to the error in the estimated area.

For this activity, I'll give myself a grade of 9.5. This is because I was able to estimate the area of various generated shapes with a small percent error.

I thank Mimie Balgos for teaching me how to install the SIP toolbox.

Monday, June 22, 2009

Activity 3: Image types and basic image enhancement

Shown are different types of images copied from the web.


Binary Image

Grayscale

True Color

Indexed Image

This activity is similar to the previous one. Again the area of a given image is to be calculated. The scanned image for this activity is show below.


The image above has a dimension of 781 X 445 and was saved in a jpeg format. It was converted into grayscale; hence 256 colors are only present.

The histogram of this image was calculated using the follow function in Scilab. Here is the snippet used.

//histogram
for i=0:255
x = find(im==i);// im is the image used
count(i+1) = sum(x);

end

scf();plot(0:255,count)


Using this code, the histogram of the image was calculated and is shown below.

Recall that in a grayscale image black is zero and white is 255. The histogram clearly shows that the object(the name kaye) which is color white is well separated from its background.

Afterwards the grayscaled image is binarized using the threshold point obtained from the histogram of the image and the function im2bw. In thresholding, a point separating the object from its background is used to map points greater than or equal to it to 1 (white) while points less than it to 0 (black).

After binarization, the same steps in area identification was done. For the shown image, the calculated area of the object (name kaye) was 131142.5 pixels. This was compared to the measured area through pixel count which was equal to 133220 and was found to have a 1.6% error.

The same process was also done for the figure below.


http://en.wikipedia.org/wiki/Coins_of_the_Philippine_peso

After binarizing the image using thresholding..


The area of this one peso coin was calculated and was compared to its analytically computed area. The calculated area was found to deviate 1.3% from the original value.


For this activity, I'll give myself a grade of 10 for I was able to calculate the area with only a 1.6% and 1.3% error for the scanned and one peso coin images, respectively. Also, I'm giving myself a two point bonus since I was able to make a code that computes and plots the histogram of an image.

I thank Miguel Sison, Jica Monsanto, Jay Samuel Combinido and Mark Jason Villangca for the KAYE-image used.

Wednesday, June 17, 2009

Activity 1 - Digital Scanning

For our first activity, we digitally replicated a graph coming from an old book. The graph that I was able to get is from the book X rays in Theory and Experiments that was published in 1935.

Here are the steps that I used in reconstructing the graph:
1. Open the scanned graph using paint.
2. Obtain the pixel values of points in the graph by placing the pointer in the designated points.
3. The origin of the image and the reconstructed graph must coincide (the origin in an image is found at upper left corner of the image). This is done by getting the absolute value of the difference of the origin's pixel value and any other points' pixel values.
4. Tabulate the measured pixel values using Excel or OpenOffice Spreadsheet.
5. By using ratio and proportion, obtain the equation relating the physical values to the pixel values and use this to interpolate points on the graph.
6. Reconstruct the graph in Excel or Spreadsheet.
7. Compare the generated and the scanned graph by overlaying the two.

Here are the results obtained.

The table above shows the pixel values (Pixel along X and Y) corresponding to the the physical values.

The figure above shows the scanned and the reconstructed graph. As one can observe there is an offset. Some points of the reconstruction are relatively far from its corresponding points on the scanned graph. This maybe because of the angled x-axis of the scanned image. I actually rotated the image in such a way that the y-axis would be vertical. However when I did that, it resulted to the angled x-axis. When I checked the hardcopy of the image, the x-axis of the graph is really tilted.

For this activity, I will give myself a grade of 9. This is because I was able to reconstruct the graph similar to that of the original although there is a slight offset.

I thank Janno Vergara for teaching me how to overlay images on a spreadsheet graph and also the College of Science Library where the book X rays in Theory and Experiments can be found.