A2: Area Estimation for Images with Defined Edges

In this activity, we were to estimate the area of images with defined edges using Green's Theorem and compare results with theoretical values from both analytical calculations and pixel counts. To ensure that the edges are well-defined, we created our own images using GIMP and MSPaint. We start off with shapes with areas that may be easily calculated analytically, a rectangle, a triangle, a circle, and a donut (Figures 1 to 3 and 5). We then estimate for the letter J and compare only the pixel count with the Green's Theorem area (Figure 6). All objects on the images for area estimation are white and on black background.

Figure 1. 130px x 100px rectangle.

Figure 2. triangle.

Figure 3. 50px radius circle.

Figure 4. 100px radius circle.

Figure 5. Donut with outer radius = 73px and inner radius = 59px.

Figure 6. Capital letter J in Comic Sans font.

For all computations, we use Scilab and the Scilab Image Processing (SIP) Toolbox. We first import the images as arrays into the Scilab session using the imread command from SIP:
Img = imread('ImageLocation\ImageFilename.jpg')
We use the follow command from SIP in getting the contour of the object but this command requires that the input image array be in 1s and 0s only. So, we binarize the image first using the im2bw command, also from SIP:
ImgBW = im2bw(Img,0.5)
Note that the threshold value of 0.5 ensures that only values higher than 0.5 are set to 1 and those less than 0.5 are set to 0. We can check if the thresholding is appropriate by visualizing the resulting image using: imshow(ImgBW).
We then use the follow command to trace the contour:
[x,y] = follow(ImgBW)
Variables x and y will then have been assigned arrays containing the x and y pixel locations, respectively, of the contour detected by follow.
Just to check if the contour was properly identified, we visualize the contour: plot(x,y). Figure 7 shows the contour for the rectangle object.
Figure 7. Rectangle contour.

We note that the contour is not closed or the starting and ending points are not connected (upper left corner), hence, we need to add the starting point at the end of [x,y]:
len = length(x) //no. of boundary pixels
//close the contour
x(len+1)=x(1)
y(len+1)=y(1)


Check if contour has been closed:
Figure 8. Closed rectangle contour.

Finally, we can compute for the area using Green's theorem:
where Nb = no. of pixels at area boundary. We implement this in Scilab by using element by element multiplication and adding to that the boundary pixel count.
len = length(x) //new no. of boundary pixels
Garea = sum(((x(1:1:len-1).*y(2:1:len))-(x(2:1:len).*y(1:1:len-1)))/2)+len/2


For the white pixel counts we simply count or add up the 1s in the image:
Parea = sum(ImgBW)
And for the analytical areas of the rectangle, triangle, and circle, respectively, we use:
Aarea = (max(x)-min(x)+1)*(max(y)-min(y)+1)
Aarea = (max(x)-min(x)+1)*(max(y)-min(y)+1)/2
Aarea = %pi*(max(x)-min(x)+1)*(max(x)-min(x)+1)/4


For the donut: Aarea = %pi*(73*73-49*49).

Table 1 shows the analytical area calculations, white pixel counts, and Green's theorem area calculations for each object.

Table 1. Analytical area calculation, white pixel counts, and Green's theorem are

The analytical estimation for the area of the circle is different from the pixel count and the Green's approximation because the circle created was not a perfect circle (made up of square pixels). And as for the very large error in the Green's estimation for the donut, the follow command was only able to identify the larger outer contour. Hence, this method of using SIP's follow command and then calculating for the area using Green's theorem may not be applied to objects with holes or those with more than one bounding contour.

I give myself a grade of 9.

I would like to thank Mr. Miguel Sison for the instructions on installing SIP for Scilab.


0 comments:

Post a Comment