Tuesday, June 17, 2008

Activity 2: Area Estimation of Images with Defined Edges

In this activity, we are asked to estimate areas of different images using Scilab. First, I created several simple images using MS Paint. My first image was a rectangle. It is important that the background is black while the shape is white. The image can be saved under any extension (.jpg, .bmp, etc). Here is the Scilab code that generates the area of this white rectangle.

rect = imread('rect.jpg'); //load image
rect = im2bw(rect,0.5); //convert to binary
[x,y] = follow(rect); //function that follows the contour
x_1(1) = x(length(x)); //create x_i+1 array
x_1(2:length(x)) = x(1:(length(x) - 1));
y_1(1) = y(length(y)); //create y_i+1 array
y_1(2:length(y)) = y(1:(length(y) - 1));
theo = (max(y)-min(y))*(max(x)-min(y)); //Theoretical Area of rectangle
A = abs(1/2*(sum((x.*y_1) - (y.*x_1)))); //Green's function for area estimation


After running the code, the theoretical area for the rectangle is theo = 13152, while the area calculated from Green's theorem is A = 13056. There is an error of 0.73%.

We can also try this method out using various shapes. For a circle, the code is similar. Just replace the image, image name, and the theoretical formula of its area.

theo = 4536
A = 4532
error = 0.09%



Again, for another circle with a smaller radius:

theo = 346
A = 341
error = 1.45%



It can be observed that there is a higher error for a smaller circle than a bigger one. This may be because a smaller circle generated in MS Paint looks less like a "real circle" due to the pixels being square. A bigger circle will look more like a circle since more pixels are being used to smoothen the circle's boundary.

In summary, the Green's method for calculating areas of images with definite edges is nice and efficient since the computed areas are within 5% error of their theoretical values.

I give myself 10 points for this activity since the computed areas were within 5% of their theoretical values. Thanks to Jeric Tugaff, Julie Dado, and Rica Mercado for their help in the Scilab code syntax and in loading the SIP toolbox.


Next time, I will try to see if this method works on a scanned image of a relatively flat object (i.e. leaf, ID, cards, etc...).

1 comments:

Jing said...

Excellent! This is indeed a 10.