Wednesday, June 24, 2009

A2.2 Area Estimation of Images with Defined Edges

Today, we used Green's theorem to estimate the area of the images that we created last tuesday (see A2.1) and compared it with the theoretical area which was obtained from the pixel count.

Green's theorem relates a double integral to a line integral using this equation:


where the functions F1, F2 and their derivatives are continuous in the region containing the area that we want to find.

If we apply the theorem to for these 2 cases (1) F1=0, F2=x and (2) F1=-y, F2=0, we can get an equation for the area of an enclosed region using


In discrete form it becomes

where (xi, yi) are the contour points of the region.


The program that I used in Scilab is as follows

close (); clc;

Im=imread('C:\Documents and Settings\2004-49537\Desktop\cherry\a2 images\car.jpg');



Im_bw= im2bw(Im,0.5);


[x,y]=follow(Im_bw);

//////// Close the contour
x(length(x) + 1)=x(1);
y(length(y) + 1)=y(1);

//figure()

plot(x,y);

//////// Area According to Green's Theorem
s=length(x);

Agreen= round(0.5 * (sum(( x(1:(s-1)).*y(2:s) - y(1:(s-1)).*x(2:s)))+s))



//////Checking

Acheck1=sum(floor(Im_bw))


The added term in the green's area calculation is because the follow command only counts the lower left contour, 0.5 s will make the upper right corner boundary included in the area.

The table below shows the comparison between the area computed using the Green's theorem and the area computed using pixel count for the images that I posted in A2.1. I also tried this for other more unsual shapes like the ones below and it still worked. In fact this will work for all regions with well defined edges or those that have no empty spaces in between (See what happens when image is a loop).

Image

Area (Green)

Area (Pixel Count)

triangle

11, 685

11, 685

square

26, 732

26, 732

rectangle

12, 640

12, 640

ellipse

13, 548

13, 548

circle

50, 000

50, 000

car

18, 383

18, 383

name

8, 766

8, 766

loop

7, 469

4, 952



I give myself a score of 10 because I fully understood and enjoyed the activity.
Reference: A2 Handout


Acknowledgement: Thanks to Miguel Sison for making my SIP toolbox work. Thanks also to Jay Samuel Combinido, Jica Monsanto and Miguel Sison for answering my questions about the activity.


1 comment:

  1. Che,

    Its good you tried out different shapes. You found the limitation of Green's function. It won't work if the contour crosses itself.

    ReplyDelete