Tuesday, June 23, 2009

Activity 2: Area Estimation of Images with Defined Edges

Area estimation finds many applications in the field of material science, biology, geology and the natural science in general . Biologists are especially interested in the difference in size between cancer cells and healthy cells. In material science, area measurement of leads and semiconductor materials among others is an effective tool for processing and failure analysis. In geology, remote sensing is an active area of research used widely in environmental and marine science researches [1].

The method below discusses image area measurement using Green's Theorem. It must be noted that before using this method, there are several limitations that must be considered. We will discuss these limitations at the end of the article.

We start with the following.
Below are sample images (256 x 256 ) of triangle, square, circle and several irregular polygons which we will use in our area estimation method.

Circle of diameter=125px, Square of side=130px, triangle of base=height=150px. These measurements are obtained from MS Paint while creating the images. It must be noted that these measurements are just guidelines for checking our results and must not be used as the theoretical area of the image. In creating these images, the border already occupied several pixels, so the area of the shape (white) does not necessarily reflect the analytically expected result. (i.e, Area_square = 130*130)

Pixel Count: 16129
Computed Area: 16129

Pixel Count: 11644
Computed Area: 11644



Pixel Count: 10731
Computed Area: 10731


Pixel Count: 17522
Computed Area: 17522


Pixel Count: 14058
Computed Area: 14056


Pixel Count: 14913
Computed Area: 7414


In order to compute the area of the above images, we use the SIP toolbox of scilab-4.1.2 using the command follow. Excerpt from the description of follow command from scilab:

"follow - A contour follower. Function follow extracts parametric contours of binary objects. This is useful for further extracting object features such as curvature and bending energy."

Note that before we use the command follow, our images must be first binarize. This can be done in scilab using the command im2bw. The command follow returns the [x,y] coordinates of the contour. We can then use this contour coordinates to compute the area using Green's Theorem found below. For more detailed discussion of area measurement using Green's Theorem please follow this source [2] (http://www.attewode.com/Calculus/AreaMeasurement/area.htm).

Since the image is binarized, we can compute the thoretical area by summing the pixels of the image (white~1 and black~0). We designated the theoretical area as "pixel count" in the above images and "computed area" when using Green's Theorem.

Below is the code in scilab used to obtain the pixel count and the computed area:

//load image
directory='C:\Documents and Settings\2004-29578\Desktop\Activities\Activity 2\'
filename='quadrilateral_130side.jpg';
img1= imread(directory+filename);

//binarize image
img2=im2bw(img1, 0.5);

//get the contour using follow
[x,y]=follow(img2);
//get the dimensions of x and y
[M,N]=size(x)
//complete the contour setting the last pixel=first pixel
x(M+1)=x(1);
y(M+1)=y(1);

plot(x,y);

//get the area using Greens Theorem. we use round since the area (number of pixels (1 or 0)) can only take //integer values.
Area = round(0.5*sum((x(1:M).*y(2:(M+1)))-(y(1:M).*x(2:(M+1)))))+ round((M+1)/2);
//pixel count
TArea = sum(img2);

//imshow to scale to grascale, i.e., highest pixel becomes white, lowest pixel becomes black
//binarize image using im2bw
//increase memory for scilab use, stacksize.


Note that in obtaining the computed area, we added a correcting factor "round((M+1)/2)" in our code where M is the length of the x or y vector.

Results and Limitations
(1) For the regular polygons and the first irregular polygon, the pixel count and the computed area are the same, meaning that the algorithm successfully estimated the area of the images.
(2) For the next irregular polygon (figure batman) there is a discrepancy in the pixel count and the computed area.
In the figure above, note the extra 2 pixels in 'batman's" horn which accounted for the discrepancy. This error is due to the command "follow" of scilab which assumes only ONE contour per image. In order to check this, we made two contours in the next image and as expected there is a huge discrepancy between the pixel count and the computed area.

(3) The algorithm and theory for computing the area is pretty solid (Green's Theorem) hence most of our errors should come from the input and processing of the input. That is, our limitations will most probably due to the command follow and im2bw of scilab.

Overlayed image of the binared square and its contour using the command follow. Note that there is an offset in the contour compared to the image of ~2 pixels. Similar observation is found in the next image.
Note the offset between the contour and the image.

(4) The command im2bw is similar to thresholding and thus depending on your threshold, the computed area will change. This effect would most probably depend on the user setting the threshold and making measurements.

(5) It is expected that in large scale images (2048x2048) the computed area will approach the analytical area. This would be very useful in applications like remote sensing and geological survey.

For this activity, I give myself a grade of 10 for exact area measurement as proven by the sets of images used.

References:

[1] Activity 2 Handout
[2] http://www.attewode.com/Calculus/AreaMeasurement/area.htm

1 comment: