Wednesday, July 1, 2009

Activity 2 | Area Estimation for Images with Defined Edges

Computing the areas of images is a very important tool in different technologies nowadays. Here in this activity the area of a binary image is computed by using Green's Theorem on computing the area of an image by using the contour of the image. From the activity manual itself, using Green's Theorem is getting the 'Area from edge.'

Green's Theorem [1] relates a double integral to a line integral as shown by the following equation where F1 and F2 are continuous functions with continuous partial derivatives that encloses the desired region or image.

This equation is then reduced into a simple summation that uses the contour of the desired region or image and is given by the next equation.

Below is generated and used code in this activity using Scilab. The procedure on what and how it is done is also shown here.

1. Load image.
rect = imread('C:\Users\Cindy\Documents\physics\ap186\A2\rectangle.jpg');
//circle = imread('C:\Users\Cindy\Documents\physics\ap186\A2\circle.jpg');

2. Convert Image from RGB to binary format using the SIP Toolbox function im2bw. Two binary images are used in this activity where one is an image of a rectangle and another is the image of a circle. Both images are created using Paint. Their analytical area is computed from the pixel dimensions given by Paint.
bw = im2bw(rect, 0.5);

3. Get the contour of the image using the SIP Toolbox function follow
[x,y] = follow(bw);

4. Implement GREEN'S THEOREM using the contour obtained.
len = length(x); //length of contour array
Aa=51012; //analytical area for rectangle
//Aa=53820; //analytical area for circle
Ac=0; //computed area

for i=1:len-1
a = (x(i)*y(i+1)) - (x(i+1)*y(i));
Ac = Ac+a;
end

5. But since the generated contour is not closed as shown in #3, we add the first value of the contour to close it to a loop.
a = (x(len)*y(1)) - (x(1)*y(len));
Ac = (Ac+a)/2

6. Check if the contour fits the original image by superimposing the contour on the original image.
imshow(rect)
plot(x,y)

7. COMPUTE PERCENT ERROR
perr = (abs(Aa - Ac)/Aa)*100

The results for each image is shown below. The analytical and computed area using Green's Theorem is given below each image.

Image 1: Rectangle
Analytical Area: 51012 px
Computed Area : 49220 px
Percent Error: 3.51%

Image 2: Circle
Analytical Area: 47143.52 px
Computed Area : 45575 px
Percent Error: 3.33%

Based on the results obtained, we can say that the method used gave a good approximation in computing the area of a region in an image. One possible source of error is the contour used which was generated by a built-in function of the SIP Toolbox. As seen from the superimposed images, the contour does not exactly fit the outline of the polygon leaving out spaces that should be included in the area.

I give myself a grade of 9 for this activity since the computed area is a close approximation of the analytically obtained area of the image as shown also by the small percent error. It is obvious enough that a major source of error is the contour used in the computation.

I thank Ms. Kaye Vergel for helping me on the basic functions of the SIP Toolbox such as the help function, imread, follow, im2bw. :D :D :D Thank you also for pointing me to the SIP Functions Reference.

Reference:
[1] UPNIP - AP186 - Activity Sheet 2 - Area Estimation for Images with Defined Edges.

No comments:

Post a Comment