Sunday, June 27, 2010

AP 186 Activity 4: Area Estimate of Images with Defined Edges

The objective of this activity is to be able to estimate the area of images that have defined edges using Green's theorem.

First, we're asked to make a black and white image of a regular object with the object being white and the background colored black. The area of the object must be known in order to compare it with the results. So I made this 150 by 80 pixel white rectangle with it's upper left corner starting at 100, 100 (origin at upper left corner) using Paint.

white rectangle (150 x 80 pixels)

And as told, I saved it in BMP format rather than JPG. So the white rectangle has an area of 150 x 80 = 12,000 pixels.

Next, let's load this into scilab and compute for the area:
I = imread("C:\shape.bmp");
[x, y] = follow(I);
xiplus1 = x;
d = xiplus1(1);
xiplus1(1) = [];
xiplus1(452) = d;
yiplus1 = y;
e = yiplus1(1);
yiplus1(1) = [];
yiplus1(452) = e;

A = 0.5 * sum((x .* yiplus1) - (y .* xiplus1))
The removal and addition of the 1st and last elements on xiplus1 and yiplus1 are just to shift it one place. x and y contains 452 elements. And fortunately, the follow function gives out the parametrized contour vectors x and y, so x and y are in coordinate system (not rows and columns).

I got the answer of 11,544 pixels which has a 3.8% error:It's a good estimate since the error's under 5%; it's a fairly accurate technique. Although personally, I was expecting it to perform better since the shape was a simple rectangle.


Now let's try the area estimation on a real location. Using Google maps, I picked the Quezon City Circle, which is bounded by the Elliptical road.

Image of Quezon City circle taken from Google Maps (click to zoom in)

Then using paint, I delineated the area of interest from the rest and the result was:

Area of interest with the edge delineated

Now using the same procedure as done above, I got the answer of 50, 549.5 pixels. In order to convert this into square meters, I use the technique in Activity 1 to determine the conversion factor from pixels to meters from the scale in Google maps.

scale bar on the bottom left corner (click to zoom in)

I have determined that 87 pixels = 200 meters (lengthwise). So that means 1 lengthwise pixel = 2.299 meters and 1 (square) pixel = 5.285 sq meters. Therefore 50, 549.5 pixels would be equivalent to:
267, 139.65 sq meters
Now's let's try to compute for the error. Since the scale bars take up two pixels:

scale bar

This means that the error would be plus/minus 1 pixel (lengthwise), which would translate to: (using error propagation)

(200/87) * (1/87) = 0.0264 meters.

Therefore the error in area per pixel would be:

(200/87)*(2)*(0.0264)*(87/200) = 0.121 sq meters

Multiplying this with our answer with 50, 469 pixels, we get the error of:
6106.75 sq meters
which is 2.29% of the result.

So the final answer is:
267, 139.65 +- 6106.75 sq meters
Finally I have to compare this with the actual value. Sadly, I can't find the area of the region inside the elliptical road on the internet so Joseph Bunao and I used Google Earth to determine the semi-major and semi-minor axis of the ellipse.

Finding the length of semi-major and of semi-minor axis

And we have determined 328.37 m and 259.65 m to be the lengths of the semi-major axis and semi-minor axis respectively. Using the formula for the area of an ellipse, we get the value:
267, 856.18 sq meters
Wow! The estimated area is very close to this value and has an error of 0.27%. This shows that the technique is accurate when dealing with images with defined edges since this will determine the contour that is used in Green's theorem.

And with that, I give myself a 10/10 for producing the requirements and understanding the lesson. The images are clear and of good quality.

Score: 10/10

Lastly I would like to thank Dr. Soriano for always entertaining my questions and Joseph Bunao for helping me find the lengths of the axes of the elliptical road.

- Dennis

References:
1. M. Soriano, "A4 - Area Estimation"
2. Google Maps

No comments:

Post a Comment