Showing posts with label Area Estimation. Show all posts
Showing posts with label Area Estimation. Show all posts

Thursday, September 23, 2010

Activity 10 - Binary Operations


In this activity, we aim to segment a particular region of interest from the background. We initially converted the image into binarized form so that the separation of the ROI from the background will be easier, taking into account the optimal threshold. We used the histogram of the image in order to determine the threshold value that will separate the ROI from the background. Figure 1 shows an image depicting normal cells imaged under a microscope. The threshold value used in binarizing the unit normal cell is 0.80. For the 12 subimages, a threshold value of 0.845 was used.

Figure 1. Image of scattered punched paper digitized using a flatbed scanner.

Figure 2. Image of a unit normal cell binarized in order to estimate the area of a unit cell.
This unit normal cell has an area of 530 pixels.
Figure 3. Histogram of the unit normal cell in Figure 2.
Figure 4. Histogram of the Total Normal Cells Area

Figure 5. Segmented Normal Cells

From Figure 5, the mean is found to be 521.85294 pixels with a standard deviation of 18.871387 .



Figure 6 shows an image of normal cells with 5 cancer cells. This image was binarized using a threshold value of 0.845. Figure 7 shows an image of a unit cancer cell. The same threshold value was used to binarized this image of unit cell. Using the histogram shown in Figure 8, the 5 cancer cells were segmented as shown in Figure 9. However, since some of the normal cells are overlapping, their combined area falls on the range of possible area of a cancer cell.


(a)
(b)
Figure 6. Normal Cells with 5 Cancer Cells

Figure 7. Unit Cancer Cell. This has an area of 1001 pixels.
Figure 8. Histogram of Total Area with Cancer Cell
Figure 9. Segmented Cancer Cell with some Normal cells.


Self-evaluation:
Credits:

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: