Area Estimation for Images with Defined Edges





Use of Green’s Theorem & Pixel Counting to determine the area



In this blog, we will estimate the area of images with defined edges. The thought really sounds cool for me but trust me, it really needs some effort to pull this one off. We will use two ways in order to estimate the area in the image: (1) by pixel counting and (2) Green’s theorem.





First, we find the area of regular geometric images such as a circle and a square. Next, we find the area of irregular shapes such as a heart and an image resembling a “twitter bird”. Lastly, we apply the two techniques to determine the area of a certain place.


For the two techniques, the image must be converted into a binary image first. The area to be computed is the white part of the image, and the rest is black. This is highly important because the algorithm we will be using assumes this.


The first technique counts the number of white pixels in the image to determine the area. In the process of counting the white pixels, I thought that the value of white pixels in the image is 1 but when I read the image, it turns out to be 255. With this, the code snippet I used is:


e = imread(‘C:UsersdellDesktopAP 186Act 4Stuffbh.bmp’);

disp(length(find(e==255)));

I just “find” the 255 values in the image using the second line.


That’s all for the first technique. Easy isn’t? XD Well, that’s only the first part. The Green’s function is a lot more tedious.


The second technique uses the Green’s function which calculates the area using an ‘edge’. I really don’t want to dig deep much into the “nosebleed”/mathematical part of the Green’s theorem. :p Green’s theorem relates a double integral to a line integral (okay, too much jargons. xD). In layman terms, we use Green’s theorem to relate a ‘line’ to an ‘area’. When we have a closed line (the shape doesn’t matter as long as it does not ‘loop’), we can calculate the area it encloses using the Green’s theorem. For our purpose which uses discrete values, the discrete form is more useful.


So, the next step now is to implement it! And this is the part where most of us got stuck. I bet if you’ll check out some of my batchmates’ blog, you’ll read many problems. First one is there is no follow() function in the newest version of SciLab; you need to install the SciLab Image Processing (SIP) module first. However, there is no working SIP module for windows users as of now. The choice is to either use a lower version of SciLab or install it in a Linux or Ubuntu operating system. As for me, I did not do any of both. Luckily, my friend Ash have found a separate follow() function that is suitable for our version! Yay! Thanks to the blog of Kuya MP, we have solved our “follow” problem. You can check out the separate follow() SciLab function script here. And since we now have a follow function, we can use it readily!


First, I have used the edge function to get the border of the shape I will be using. Next is I execute the “follow()” function script. And then, I get the x and y values of the pixels of the outline (from the edge function) using the follow function. This gives me a clockwise “sweep” of the outline’s pixels. Note that this is important in using Green’s function. The third to the last line of the code above “closes” the contour of the integral. And now, after hours of contemplation, we test the code. First, we test it on geometric shapes: (1) circle and (2) square. Here is what we got:



From the two geometric shapes, it is seen that an error of 0.01 to 2% is calculated. Next is we apply the code to non-geometric image. This is how it looked like:


The non-geometric shapes’ area from the pixel counting and Green’s function deviates from each other by 0.2% and 0.3%. For the last part of the experiment, I have used an image of an underwater sinkhole (Belize) and calculated its area. Figure 6 shows a view of it. Note that is is not the image I have used. I used the image in google maps to calculate the area which is seen in Figure 7.


Figure 6. An underwater sinkhole. Image from National Geographic Website.


I have calculated the area in four ways:

  1. From literature value, I have found that the sinkhole stretches about 300 meter across (http://belize.com/belize-blue-hole). From geometry, I have calculated the area is: 70685.835 m2
  2. From the image itself (actual sinkhole), I have measured the diameter to be 68 pixels. This translates to an area of about 3631 px2. Now, converting it to meters, I have used the markings on the map. From inspection, I have seen that 500 meters in the map corresponds to 111 pixels. This means that there are 4.5 meters in 1 pixel or 20.3 meter squares in 1 pixel square. Multiplying 20.3 by 3631 px2, the area calculated using this method is 73688.846 m2.
  3. Using pixel counting, the value of the area is found to be 73999.675 m2 (this is after multiplying the scaling factor to 3647 px2).
  4. Using Green’s function I calculated it to be 74293.888 m2.


The values are really not much away from each other considering the nature of the method. The largest is about 5%.


Warning! For those who will try this out, be careful in using the edge function. Sometimes, it gives out an outline with some discrepancies or holes in it. This gives out wrong area values (sometimes it even gives out zero or negative numbers!).