Wednesday, June 24, 2009

Activity 2: Area Estimation for Images with Defined Edges

For this activity, Green's theorem is used to estimate the area of a binary image with defined edges. The edges of the images were obtained using the "follow" command in Scilab. Area estimation of Green's theorem is
The theoretical value for the area was obtained by counting how many pixels with values of 1.

The code

1 Image=imread("C:\Documents and Settings\mimie\Desktop\hand.bmp"); //read image file
2 I = im2bw(Image,1); //convert image to binary
3
4 [x,y]=follow(I); //get the contour of the image
5 A=[];
6 lx=length(x);
7 ly=length(y);
8
9 //close the contour
10 x(lx + 1)=x(1);
11 y(ly + 1)=y(1);
12
13 for i=2:lx;
14 A(i) = (x(i)*y(i+1))-(x(i+1)*y(i)); //area of the ith triangle
15 end
16
17 Area = (0.5*sum(A)) //Green's Theorem
18 theo = sum(I)
19 err = abs((Area-theo)/theo);
20 %err = 100.*err //percent error



The above code is implemented on the images below:


















with the following results






The error is mainly because of the "follow" command. Since this command is a contour follower, the effective area as estimated by the Green's theorem is lessen by the pixel counts containing the contour. For example a 100x100 square image should have an area of 10000. Using the code above, an area of 9806 is obtained which corresponds to about 99x99 square. This means that the calculation for area starts inside the contour and not at the contour itself. To compensate this, an extra 0.5 lx term is subtracted from the pixel count
(line 18: theo = sum(I) - 0.5*lx). The relative error is lessened when this is done.

Raffy and Cherry helped me in this activity. Thank you also to Miguel for troubleshooting the SIP toolbox. For this activity, I give myself a 9/10.

No comments:

Post a Comment