Monday, July 6, 2009

Act 5: Fourier Transform Model of Image Formation

In this activity, the various applications of the fast Fourier transform (FFT) were applied. The FFT was implemented using Scilab 4's various FFT functions.

A. Familiarization with discrete FFT
First we were required to perform 2-D FFT, inverse FFT, as well as performing 2-D FFT twice on the same image.
The first image used was this circle:


And the outputs produced were:

The next image used was the letter "A":

And the outputs produced were:



B. Simulation of an Imaging Device

The second part of the activity requires the convolution of this image


to circles of various sizes


The circle is to act as the aperture for the "VIP" image, since a lens basically acts as an FFT to an image. The output is as follows



C. Template Matching using correlation
The third part of the activity makes use of correlation in order to find patterns in an image. This was shown by correlating these two images:

so that the A's in the image can be seen. The output of the correlation is this image:


D. Edge detection using the convolution integral
The final part of the activity requires the convolution of various 3x3 matrices with this image:


The matrices used were as follows:
vertical: horizontal: diagonal: spot:
[-1 -1 -1] [-1 2 -1] [-1 -1 2] [-1 -1 -1]
[ 2 2 2] [-1 2 -1] [-1 2 -1] [-1 8 -1]
[-1 -1 -1] [-1 2 -1] [ 2 -1 2] [-1 -1 -1]

The output images are as follows:


What happens is that the matrix pattern highlights the edge that is related to it. For example, in the first image, the original image was convolved with a horizontal matrix, thus resulting to the horizontal parts of the edge of the image being highlighted.

I would like to grade myself 10/10 for fully accomplishing this activity in the given time. Also, I would like to thank Earl and Raffy for helping me improve my code.

Act 4: Enhancement by Histogram Manipulation

In this activity, we make use of a small (256x256 pixel) image:

Its graylevel probability distribution function (PDF), and cumulative distribution function (CDF) are shown below:

above: PDF, below: cdf
Since the CD of a uniform distribution is a straight increasing line. A straight line was then plotted to serve as an idealized CDF. The image was then backprojected onto this new CDF and a new CDF was obtained. Their respective plots are shown below:

above: ideal CDF, mid: new PDF, below: new CDF
And the resulting image is shown below

For the nonlinear response, instead of a straight line, we make use of cubic function (x^3). The idealized CDF, the backprojected histogram and the new CD resulting from the backprojection is shown below:

And the resulting image is shown below:

It can be observed that the linear response has higher contrast compared to the nonlinear distribution, but the image quality of the nonlinear image is much better compared to the linear one.

I will grade myself 10/10 for being able to successfully backproject and render the image for both linear and nonlinear functions. I would like to thank Earl for the discussions and Gilbert for the snippet which enabled me to continue with the code properly.

Monday, June 22, 2009

Act 3: Image types and basic image enhancement

For this activity, we were required to collect images of various formats. For this, I have chosen the following:


Binary: the "John Hancock" signature
(image courtesy of http://upload.wikimedia.org/wikipedia/commons/thumb/9/90/JohnHancockSignature.svg/384px-JohnHancockSignature.svg.png)





Greyscale:
Charlie Chaplin
(image courtesy of http://www.europeancourier.org/118.htm)














Indexed:
Van Gogh's "Starry Night"
(image courtesy of http://www.wpclipart.com/art/Paintings/Van_Gogh/VanGogh_starry_night.png.html)











True Color:
the Great Barrier Reef
(image courtesy of http://www.gmcc-09.com/welcome-to-melbourne/the-country/)









Aside from finding various images on the internet, we are also required to scan an object, preferably with a distinct border. Along with Earl, I used a map of Japan:

except in my activity, I chose Kyushu to be my region of interest. The image was binarized, and the following image was obtained:

It is now possible to apply the follow function in order to obtain the contour of the image so that it becomes possible to apply the Green’ s theorem and obtain the area of the image. The area can also be computed by taking the sum of the image since the binary image is simply composed of ones, which represent the white parts of the image, and zeroes, which represent the black parts of the image. Hence, the area of the image is effectively its sum.

The obtained values were:
using Green's theorem: 17946 pixels
using summation: 18600 pixels
% deviation: 3.5161%

The values obtained are sufficiently close to each other. By taking the length of the scale in terms
of pixels, the area of Kyushu can then be calculated by mere conversion.

I will give myself a grade of 10/10 for this activity since the previously learned lessons were successfully applied for this activity. I would like to thank Earl for sharing with me his scanned image of Japan.

Act 2: Area Estimation of Images with Defined Edges

For this activity, I have used MS Paint to construct the following images:

1. Square
The square has one side measuring 298 pixels, thus the square has 88804 sq. pixels.

2. Rectangle
The rectangle has dimensions 400 x 298 pixels, thus the rectangle's area is l x w = 119200 sq. pixels.

3. Circle
The circle has radius of roughly 147 pixels, thus its area is pi*radius^2 = 67886.676..., which we round down to 67887 sq. pixels.

4. Triangle
The triangle has base of 350 pixels and height of 217, thus its area is 0.5*base*height=37975 sq. pixels.

All images are 500x500 pixels and are originally in bitmap (.bmp) format. I compressed them to jpeg (.jpg) format to make uploading easier.

In order to find the area of the shapes, Green's function was to be used:
In a nutshell, what Green's function does is to slice up a certain figure, take the area of each individual slice, and take the sum of all the slices, yielding the total area of the figure.

To implement Green's function computationally, the following Scilab 4 code was used:
[fig, figmap] = imread('F:/Applied Physics 186/Activity 02/shape.bmp');
[x, y] = follow(fig);
n=length(x);
B=0;
for i=1:n-1,
A = (0.5*(x(i)*y(i+1)-x(i+1)*y(i)));,
B = B+A;,
end;
B
The function follow gives the coordinates of the contour of the figure, while the for loop basically implements the above equation using the contour obtained from follow. B simply displays the output of the summation, or rather, the total area of the figures.

The output of the code, as well as the percent error compared to the manually calculated area is tabulated below:
For this activity, I will grade myself 10/10 for having % error values less than 1%, which means that the Green's function is highly accurate, and is suitable for finding the area of irregular shapes, so long as it has a definite and continuous contour.

I would like to acknowledge Earl and Gary for their insightful discussions with me regarding this activity.

Sunday, June 21, 2009

Act 1: Digital Scanning

In this activity, we were to recreate a hand-drawn graph into digital form using a scanned copy of the said graph and a spreadsheet program such as OpenOffice or Excel.
Due to my assumption that linear graphs were ideal for this activity, I opted to use one. Unfortunately, the graph that I got had its axes in logarithmic scale and as a result, accomplishing it was much more difficult than I expected. After exhausting almost the whole period on the graph, I decided it would be much easier to use a different one. Fortunately, Earl had another graph on the second page of his scanned copy, and thus I was able to use it instead. The source of the new graph was Fesbach’s and Lomon’s The Boundary Condition Model of Strong Interactions at page 63. Also, I was told the original graph can be used in the special project since it was challenging, and at the same time, nobody has done it before (as far as I know). In any case, the process goes as follows: The image was cropped in order to isolate the graph from the rest of the scan using Nero PhotoSnap Viewer Essentials. From there, the dimensions of the graph in terms of the number of pixels were recorded.

Since my graph had two parts with different y-axis dimensions, I chose to split and separately accomplish both graphs. For both cases I chose to crop each of the main plots, discarding the values of the axes in the outside. This is because obtaining the pixel coordinates is much easier this way, and at the same time, the cropped images can be readily used as background for the reconstructed graphs later. I recorded the coordinates of the points on the graph as well as a number of representative points for the trend line using MS Paint. Since the axis of the y-axis is inverted, i.e. downwards is the positive direction, I subtracted the obtained values for the y-coordinates from the total height of the image in terms of its pixels. The ratio of the total length of the graph over the total number of pixels was obtained and used as a multiplying factor for the coordinates, which yields the physical values for the graph. The pixel coordinates for both the points and the trend line's representative points are tabulated below:


This was done for both the points and the trend line plot, except that error bars had to be added to the points.

I plotted the points on an X-Y scatter graph using Microsoft Excel. The scales were formatted so that the ticks and the values resemble those which are on the original graph. The two split graphs were then reconnected.

The representative points in the trend line are shown in the image below:

In order to better show the quality of the reconstruction, the plot area’s background was set to the cropped images:

While not perfect, it can be observed that the obtained digital plot resembles the original hand-drawn plots of the book. One of the major problems encountered in the new graph was that I had no idea how to change the y-axis scale. Thus, I simply chose to reconstruct it by accomplishing two different graphs and the grouping the two together.

Overall, I would give myself a grade of 9/10. The graph was reproduced, points, trend line, error bars and all. The main gripe I have is that I used MS Excel 2007 for plotting, which may have made the process tad easier. Also, the scale’s values weren’t the same as the original, but it was merely a matter of visual display and it doesn’t really affect the actual scale of the original graph itself.

Again, loads of thanks to Earl, for giving me the new graph, as well as for Gilbert, for a few tips on the activity, as well as uploading my blog site to the AP186 Google Group.

Monday, June 15, 2009

Hello world!

Magandang araw sa inyong lahat!