Monday, June 22, 2009

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.

No comments:

Post a Comment