Monday, July 22, 2013

A5 - Area Estimation for Images with Defined Edges


    Green's Theorem is a very useful way to compute areas ( or perimeters) of regions if one or the other is known. Supposing we have region R similar to the one shown in the Figure below

If we  take the counterclockwise direction to be the positive one then Green's theorem is given by


If we take C to be the collection of points in the boundary of R , choosing F1 = 0 and F2 = x gives us the equation below each relating a closed line integral to the area of R





Adding the two equations and averaging, we get

Which written in summation form and setting Nb to be t he number of pixels in the boundary of R then we have

I first created a circle of radius 0.7 using a code similar to the one I used in the Activity Scilab basics

stacksize(100000000);
nx = 500; //defines the number of elements along x and \y
ny = 500;
x = linspace(-1,1,nx);//defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);//creates two 2-D arrays of xand y coordinates
r = sqrt(X.^2 + Y.^2);//note element-per-elementsquaring of X and Y
A = zeros(nx,ny);
A(find(r<0.701)) = 1;
imshow(A);

with theoretical area pi*.7^2 = 1.53938



using the code 


nx = 500; ny = 500; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates
r= 0.401; // side of the square
S = zeros (nx,ny);
S (find (abs(X)<r & abs (Y)<r))=1;
imshow(S);
to form a square of side .4 with theoretical area .16





No comments:

Post a Comment