Monday, August 9, 2010

Activity 4 - Area estimation of images with defined edges

By definition, a polygonal region is a plane figure formed from the union of a finite number of triangular regions. For every polygonal region, there corresponds a unique positive real number, called area. The area of a polygonal region depends on its size and shape.[1] Since a polygonal region is a union of triangular regions, then the area of the union is the sum of the area of the triangular regions. For triangles, quadrilaterals and regular polygons, equations of area are known and straightforward. Whereas, for geometric figures with arbitrary shapes or irregularity, area measurement is challenging.


In this activity, one of the two techniques in obtaining the area of images is demonstrated. By theory, Green’s theorem relates a double integral to a line integral. If we let R defines the region we want to be estimated, and let F1 and F2 be continuous functions with continuous partial derivatives everywhere in some region or domain containing R. Equation (1) shows the relationship between double integral and line integral. [2]


Assuming F1 = 0, F2 = x and F1 = -y and F2 = 0, Equation (1) can be simplified as shown in Equation (2). This expression defines the area A of the region R.


Equation 1

Equation 2


For discrete values, if there are Nb pixels in the boundary or contour of region R of a desired image, then the area of the region is given by Equation (3).

Equation 3

To illustrate, Figures 1 shows three regular geometric shapes with known equations of area (the images shown are not the actual size). Table 1 summarizes the area of the geometric figures using the known formula and the Green’s Theorem. Percent differences were calculated to determine the accuracy of the Green’s Theorem in estimating the area of a given region.


Figure 1. (a) 480 by 480 px square (b) 360 by 480 px rectangle (c) circle with 480 px diameter



Table 1. Summary of the Calculated and Estimated Areas of Regular Geometric Shapes

Geometric Figure

Dimensions (pixels)

Calculated using Equation of Area (pixel^2)

Calculated using Green’s Theorem

(pixel^2)

% Difference

Square

480 by 480

230400

229441

0.4162326

Rectangle

360 by 480

172800

171961

0.4855324

Circle

Diameter= 480

180955.74

179687

0.7011310



In order to define the line integral that defines the contour of the region of interest, scilab function follow is used. This function obtains the edge pixel coordinates of the shape. The following code shows how the values summarized in the are obtained.



+ + + Start of the Code + + +


nx = 600; ny = 600; //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 x and y coordinates

//Create a regular geometric shape

//centered square

A = zeros(nx,ny);

b = 0.8;

A(find(((abs(X)

scf(1); imshow(A,[]);

imwrite(A, 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 4\centered_square.bmp');

ExArea = (b*nx)*(b*ny); //expected area using the known equation

//centered rectangle

A = zeros(nx,ny);

a = 0.6;

b = 0.8;

A(find(((abs(X)

scf(1); imshow(A,[]);

imwrite(A, 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 4\centered_rectangle.bmp');

ExArea = (a*nx)*(b*ny); //expected area using the known equation

//centered circle

A = zeros(nx,ny);

R = sqrt(X.^2 + Y.^2);

b = 0.8;

A(find((abs(R)

scf(1); imshow(A,[]);

imwrite(A, 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 4\centered_circle.bmp');

ExArea = %pi*(b*nx/2)^2; //expected area using the known equation

[x,y] = follow(I); //determine coordinates of the contour

//Area Estimation using Green's Theorem

k = size(x);

N = k(1,1);

A = 0;

for i = 1:N

A = A + (x(1,1)*y(2,1) - y(1,1)*x(2,1));

xx = x;

xtemp = x(1,1);

xx(1:N-1,1) = x(2:N,1);

xx(N,1) = x(1,1);

x = xx;

yy = y;

ytemp = y(1,1);

yy(1:N-1,1) = y(2:N,1);

yy(N,1) = y(1,1);

y = yy;

end

A = 0.5*A;

Area = A;

PerDiff = 100*(abs(ExArea-Area)/ExArea);



+ + + End of the Code + + +


Since the calculated percent differences are significantly small, we can say that the written code using the Green’s Thereom can correctly estimate the area of a region. For the application, Figure 2 shows an image of a map of a particular place is obtained using Google Map. The same code is used for the area estimation of the region of interest. The image was taken from a map, hence, necessary calibration must be done in the area (originally calculated in pixel^2). The calibration constant is determined from the equivalence of 126 pixels to 100 m. The known area of the Manila Botanical Garden Zoo is about 5.5 hectares [3]. The estimated area using the Green’s theorem is 58830.625 sq meters, and this differed by about 6.965 %.



Figure 2. Image taken from Google Map


Figure 3. Binarized image of the region of interest



+ + + Start of the Code + + +


//Load image to be measured

I = imread('C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 4\manilazoobot.png');

I = im2bw(I,0.5);

//scf(2); imshow(I);

[x,y] = follow(I);

ExArea = 5.5*10000; //expected area of the region of interest (in sq meters)

//Area Estimation using Green's Theorem

k = size(x);

N = k(1,1);

A = 0;

for i = 1:N

A = A + (x(1,1)*y(2,1) - y(1,1)*x(2,1));

xx = x;

xtemp = x(1,1);

xx(1:N-1,1) = x(2:N,1);

xx(N,1) = x(1,1);

x = xx;

yy = y;

ytemp = y(1,1);

yy(1:N-1,1) = y(2:N,1);

yy(N,1) = y(1,1);

y = yy;

end

A = 0.5*A;

Area = A; //in sq pixels

//Calibrate the values

C = 100/(143-17); //calibration constant

Area = A*(C^2);

PerDiff = 100*(abs(ExArea-Area)/ExArea);

+ + + End of the Code + + +


References:

[1] Moise and Downs, Geometry, Addison Wesley Publishing Company, 1991.

[2] M.N. Soriano," Applied Physics 186 - Area estimation of images with defined edges", 2010.

[3] http://en.wikipedia.org/wiki/Manila_Zoological_and_Botanical_Garden



Credits:
Self Evaluation: