Wednesday, June 24, 2009

Activity 2: Area Estimation for Images with Defined Edges

To compute for the area of arbitrary binary images, we will make use of Green's theorem. The test images are as follow

Figure 1. Rectangle with dimension190x115


Figure 2. Ellipse which can be enclosed in a rectangle of dimension 200x100

Figure 3. Irregular shape.

Figure 4. Image containing two contours.

The results are as follows

Table 1. Summary of results.
The results from the sum() function serves as the theoretical value since it literally gives area of the white region (in pixels) of a binary image. For shapes with a single continuous contour, sum() and Green's theorem methods are in agreement. Green's theorem fails with shapes having two contours as with figure 4. Below is the code used for this activity

//Scilab code. Special thanks to Miguel Sison for figuring out how to run the SIP toolbox.

chdir('C:\Users\Mark Jayson\Documents\Physics\APhysics 186\Act 2');
//read image
I=imread('ireg.png');

I=im2bw(I,0.5);

[x,y]=follow(I);

temp=0;

for i=1:length(x)-1
temp=temp+(x(i)*y(i+1)-x(i+1)*y(i));
end

temp=temp+(x(length(x))*y(1)-x(1)*y(length(y)));

A=0.5*(temp+length(x))+1 //the length(x) term is necessary to include the contour itself in the area calculation. Plus 1 is need to close the contour.

theo=sum(sum(I))

er=(A-theo)/theo

For this activity I'll give myself a 9.0. I posted it a little late because I have to figure out what went wrong to my initial code. ^_^

No comments:

Post a Comment