Activity 4: Area estimation of images with defined edges




Usually from movies (specifically action movies involving satellite images), one would wonder, how were they able to know how large the base of the terrorist just by looking at the image, without having any surveillance at that place. [Sorry, I'm a big fan of Chuck where satellite images are always shown.. :P]  From this activity, it will show how you can actually measure the area of a specific image (from map, etc), and how accurate it is.


There are two ways to know the area, that is by pixel counting or Green's Theorem, then multiply the appropriate scale.

Pixel Counting


The easier way is the pixel counting where you basically convert your image into black and white, and then count how many pixels are black or white (depending on which color is the area you wish to know).  This conversion to black and white image was already done in the previous activity (Activity 3) so you may refer to that for the code used.  Additional lines were ran to be able to count the number of pixels (of interest)

Green's Theorem

Green's Theorem basically relates the double integral (which represents the area of a region) to the line integral (which represents the boundary, or contour of the same region).  Therefore from given a region R, the area can be estimated.

Region R with contour C in taken counterclockwise direction


Assumptions 1:  F1 and F2 are continuous functions with partial derivatives with respect to y and x (accordingly) everywhere in the region containing R.

Therefor the equation for the Green's Theorem is



Allow the boundary to traverse in a clockwise direction around region R.  Let C be the collection of contour points (x,y).

Assumption 2: F1=0, F2=x and F1=-y, F2=0

Using the equation and the assumptions, we can therefore further simplify given that the double integral of dx and dy over the region R is the area, the total area is given by equation (2) above.

Now, for discrete form (since in coding, we can only integrate in discrete values, the area is given by:



In SIMPLER TERMS (another proof..)


Region (polygon) divided into different pie slices


Imagine a region where you choose a reference point at the center.  Not like a multi-sided polygon, you can basically reduce the large area into different triangular shapes (like pie slices).  So knowing the contour points C, you can know the area of each pie as shown in the figure below.

Area of one pie slice with illustrated area divisions per part (top) 
and area calculation for one pie slice (bottom)


Notice that the reference is at the origin and we move from one contour point to another (point 1 to point 2).  We can now divide the single 'pie' to four parts according to its x and y values.  The total area is reduced to the equation above.

Comparing two methods

There are basically a few steps to be done:
             **Choose an image of the area of interest
             **Apply conversion to B/W image to get desired area (adjust threshold)
             **Identify the edges of the area of interest
             **Arrange the order of points to follow a closed contour line enclosing the surface
             **Calculate area using: Green's Theorem and pixel counting [from formula]
             **Compare the difference with calculated area (% error) if possible
             **Conversion of the pixel area to actual area (if possible)

So for example, the areas of a square (side=200pixels*0.6), and a circle (diameter=200*0.4) were identified using both methods.  



Actual Area: 5026.5482
Area by pixel counting: 4984
% error: 0.8464705 %
Area by Green's Theorem: 4981
% error: 0.9061536 %



Actual Area: 14400
Area by pixel counting: 14641
% error: 1.6736111 %
Area by Green's Theorem: 14638
% error: 1.6527778 %







Applying on other images

Google Earth snapshot of the Royal Garden, Golf and Country Club in Angeles City, Pampanga


Look at this place! I mean, from my research, it has a 72-par golf course (approximately 40 hectares) plus the additional land area for other buildings.

Google maps snapshot of the Country Club in Pampanga


I was able to get an image from Google Maps of the Royal Garden and Golf Country Club (Pampanga) as shown in the image above.  Using Gimp, I removed the label of the placed.  Then applying the program from previous activity (Activity 3) with a bit of changes such as the threshold value, I was able to obtain a black and white image with the black indicating the place.  

Cropped black and white image of the area of interest (black)


Using the snipping tool of Gimp, I cropped the area of interest.  With this, varying the value for the condition of the pixel counting (from >255 to <255), the same program was applied (for area estimation).  The traced contour (green) with the reference point (red) is shown in the image below.

Contour line of the area of interest (green line) with the reference point (red point)


Now we note that this is the area in pixels.  In order to know the actual estimation of the place, we get the scale from pixel to meters using the Gimp rectangular tool as shown in the figure below.

Scaling factor of the image (87 pixels for every 200 meters)


We are able to get a scale factor of 200 meters/ 87 pixels (in x), so the area per pixel is 2.2988506.  Using this scale, we can now convert the area in pixels (for both methods) to their area estimation in square meters.  The results are as follows:

Area by pixel counting: 109551 pixels
Area by pixel counting (scaled): 578945.7 square meters
Area by Green's Theorem: 109605 pixels
Area by Green's Theorem (scaled): 579231.07 square meters
Difference in pixels: 54 pixels
Difference in square meters: 285.37455 square meters

For this activity, I give myself a 10 since I was able to finish all the required output.  There is also the effort to produce a program that is works similarly with the follow() of the SIP toolbox.  Thanks Ma'am Jing for the clue on the angles.  I was going for the arrangement per quadrant but this was a bit easier to do compared to what I have thought, even shorter code.  Thanks Angelie, I can finally install Ubuntu! Thanks Zaldy, I'm already installing the Scilab 4.XX version you gave me (will download the SIP later..)


References:
1. http://maps.google.com.ph/
2. http://www.royalgardengolf.com/Default.aspx
3. http://www.tvfanatic.com/2011/10/tv-ratings-report-chuck-bombs-grimm-impresses/ (for the Chuck image)
4. "Area Estimation of Images with Defined Edges 2012", Dr. Maricor Soriano

Comments

Popular posts from this blog

Activity 2: Scilab Basics

Activity 10: Applications of Morphological Operations - Looping through Images

Activity 11: Color Image Segmentation