Length and Area Estimation

The aim in this activity is to calculate the area of images using Green’s Theorem and through morphological operations.

First, the area of regular geometric shapes was calculated. A circle and square were produced as in the activity Scilab Basics and was saved as an image using the imwrite() function from the SIVP Toolbox.

circ_png           square_png

Using the edge() function, the edges of the shapes were obtained:

circ_edge_png         square_edge_png

Then, pixel coordinates (x, y) of the edges were extracted using find() and were translated by subtracting the centroid. For these images the centroid is just the center of the image. Then, the angle θ = atan(y, x) was calculated for all the points of the edge. The (x, y) pairs were then sorted according to increasing θ. The sorted (x, y) pairs define the contour of the edge. This was implemented in Scilab using the lines:

while i < n,
    j = find(theta == theta_sorted(i));
    [r, s] = size(j);
    for k = 1:s
        xcon($+1) = x_e(j(k))
        ycon($+1) = y_e(j(k))
    end
    i = i + s
end

where (xcon, ycon) are the lists of x and y contour coordinates, (x_e, y_e) are the lists of x and y edge coordinates, theta is the list of angles and theta_sorted is the list of sorted angles. The for loop was necessary for the cases where there are more than 1 indices returned by the find() function.

Using Green’s theorem, the area of each shape was calculted using the formula [1]:

A = \frac{1}{2}\sum\limits_{i=1}^{N_b}[x_i y_{i+1} - y_i x_{i+1}]

For the circle, an area of 17529 px2 was calculated while the actual area is 17671 px2. For the square, an area of 22465 px2 was calculated while the actual area is 22500 px2. The calculations yielded percent errors of 0.80% and 0.15% for the circle and square, respectively.

The same method was performed on the lot area of the Enchanted Kingdom theme park in Santa Rosa City, Laguna, Philippines. An image of the lot was obtained from google maps and was delineated usng GIMP 2.8:

ek2         ek2d

The only difference in the method was that the centroid had to be calculated first since the shape of the lot is irregular. This was done by averaging the pixel locations of the part of the image occupied by the lot. The edge of the image was again obtained using the edge() function:

ek_edge

The area was then converted into actual units by measuring the pixels of the absolute scale shown in the Google map. The calculated area was 16.3 hectares while the actual lot area is 17 hectares [2]. This yields a percent error 4%.

Lastly, using the ImageJ application, a scanned image of my ID was analyzed:

Using the straight line tool, I drew a line along the shorter edge of the image. I also measured its actual distance using a ruler. Then, I set the scale using Analyze > Set Scale by entering the actual distance. Then I was able to measure the longer edge of the image using Analyze > Measure. The calculated length was 84.5 mm while the actual length was 86 mm. After selecting the whole image, its area was calculated using Measure. The resulting area was 4562 mm2 while the actual area is 4644 mm2. This yields a percent error of  1.7%. ImageJ uses morphological operations which are estimations done by counting pixels. We can see that it was successful in calculating lengths and areas with small errors.

I also used ImageJ to calculate the area of the delineated image of the Enchanted Kingdom lot. The calculated area was 16.99 h and confirms the credibility of the actual area taken from the source. Since all calculations have minimal errors, I am going to rate myself with 10/10. I had fun with programming the area calculation using Green’s Theorem especially with the challenging part for me which was the sorting of the coordinates according to increasing angle since I am still new to Scilab.

References:

  1. M. Soriano, “A4 – Length and Area Estimation in Images,” Applied Physics 186, National Institute of Physics, 2014.
  2. “Enchanted Kingdom,” Wikipedia. (en.wikipedia.org/wiki/Enchanted_Kingdom)

Leave a comment