Sunday, December 20, 2009

[Review] A2 : Area estimation of images with defined edges

Area estimation is used in wide range of applications like medical (to test whether a blood or tissue sample contain cancer cells), automation (inspecting circuits and boards) and remote sensing. In these fields, the image concerned may not be as simple as the regular polygons or shapes/blobs, in fact, many of them are arbitrary.[1]

In this activity, area measurement (or estimation) of images with defined images is performed. The technique used to estimate the area is based on Green's Theorem. Green's Theorem relates a line integral around a closed region to a double integral over the said region. The formula for
Green's Theorem is shown below:


Green's Theorem

According to this website [2], the left hand side of Green's Theorem can be traced to the third
component of a curl (for the z-axis). Curl is defined as a vector operation that describes the rotation of a vector field. According to [2], we could imagine the line integral as a circulation path of a field vector of the region inside it.

A line integral can be thought of as a field circulation.


We could then breakdown this one-big "circulation" into "micro-circulations" around points inside it, as shown in the figure below:
"Microcirculations" around points inside the region

Adding up all these "micro-circulations" inside the regions is the same as getting the integral of all the circulations inside it. These micro-circulations can be thought of vector rotations that can be measured using curls. And the component of the curl corresponding to the z-axis (to the vector perpendicular to the region (or plane) is the same as the left hand side of the

The images that were used in this activity is shown below:



Triangle with 200pixel base and height

Square with 200 pixel side

Rectangle with 100pixel base and 250pixel height

Circle with 250pixel radius

And shown below is the table showing the area of the regular shapes computed using Green's Theorem and the sum() function in SciLab:

Results obtained

Though the shapes used have predetermined dimensions, using the output of the sum() function would be a much more accurate value for the theoretical area. One reason is that the final dimension of the shapes will be determined after an im2bw() operation and depending on the threshold used for the said operation, some pixels might be excluded or included in the final image to be used.

To solve for the area estimate using Green's Theorem, a simplified presentation of the Green's Theorem was utilized. If, for any closed (convex) region, we would divide it into triangles (simila to a pizza pie), we would be able to calculate the total area of the region by calculating the area of each triangle and summing it all afterwards. The method is presented in an illustration below [1]:


Therefore, given the coordinates (vectors of x and y) of the boundary, we would be able to solve for the area.

Although the error difference between the theoretical value and the Green's Theorem value is within tolerable limits (below 1 percent), it is still worthwhile to know where the error is coming from. It turns out to be (after a long analysis, and trial-and-error) that the follow() function in SciLab excludes the outermost layer of pixels and these pixels are the source of error. To compensate for this error, a value equal to 1 plus half the number of boundary pixels.

It was also discovered that follow() could not be used for shapes that has more than 1 contour, and hence, can not be used in estimating areas using Green's Theorem. This inability can be illustrated by illustrated by performing Green's Algorithm in the following images showing the letter "F" and the letter "P" :




The following table shows the estimated area using Green's Theorem:

It can be seen that for the letter "F", Green's Theorem worked just as expected. However, for the letter "P", the follow() command was only able detect the outer contour of the letter and included the space inside the loop of the head in the estimated area. This caused the program to overestimate the area, which can be numerically verified using the table above.

I give myself a grade of 9 for fulfilling the requirements. I did have some difficulty finding the source of error in the estimated area by using Green's Theorem.

Program Code:

// open the image
function [computed, theoretical, green, percentage_error] = act2(image)
currentimage = imread(image);
imageBW = im2bw(currentimage, 0.5);
//imshow(imageBW);
[x,y] = follow(imageBW);
//xbasc();
//plot2d(x,y);
theo_area = sum(imageBW);
counter = length(x);
//adjust x and y vectors to x+1 and y+1
tempx = x(1);
tempy = y(1);
xplus1(1:1:length(x)-1) = x(2:1:length(x));
xplus1(length(x)) = tempx;
yplus1(1:1:length(y)-1) = y(2:1:length(y));
yplus1(length(y)) = tempy;

// apply green's theorem
green= 0.5*(sum(x.*yplus1)-sum(xplus1.*y));


// compute additional area to compensate error
com_area = 0.5*counter + 1;
green_area = green + com_area;
computed = green_area;
theoretical = theo_area;
percentage_error = double(double(theo_area-green_area)/double(theo_area));

endfunction

[1] Maam Maricor's Activity 2 Handout