Wednesday, June 30, 2010

Area Estimation using Green's Theorem

Importance and Applications of Measuring the Area from Images
  • Cancer Research
  • Remote sensing (Land Area Estimation)
  • automated product inspection
  • and more..
Techniques to obtain the area of images
  • Green's Theorem - relates the double integral on the surface of the region to the line integral on the boundary of the same region
  • Morphological operation - consider connected pixels as blobs. Area estimation is then done by counting the pixels in the blob.
For this activity, I will be using Green's theorem in order to estimate the area of the closed contour in the image. To have a better understanding of how Green's theorem can be used to estimate the area, please click here.

I will be doing numerical computations, hence the discrete form of Green's Theorem will be much useful. Equation 1 presents us with the discrete Green's Function.

Equation 1: Discrete Green's Function. A is the area of the region. Nb is the number of pixels in the boundary or contour of the region.


Figure 1: Black and White rectangle made using Paint. By using follow() function in Scilab, the boundary of the white cavity was obtained. The four corners of this cavity are (42, 281), (42,44),(359,44) and ( 359,281).

Figure 1 shows a black and white rectangle made in Paint. By using the follow() function in Scilab, I was able to identify the four corners of the white region, and effectively determine its area. Its area, as I found out, is 75129 pixel size squared. Then, by using code 1, with the implementation of Green's theorem, I also obtained an area of 75129 pixel size squared.

CODE 1:
rec = imread('C:\Documents and Settings\andy polinar\Desktop\ap 186\activities\activity 4\shapes\rectangletrue.bmp'); //open the image file
imshow(rec); //display the rectangle

[rx,ry] = follow(rec); //coordinates of the boundary
Nb = 1107; //1108 is the total number of pixels in the boundary
presumrec = zeros(1,Nb+1);

//computing for presum and eventually the area.
for i = 1:Nb presumrec(1,i) = rx(i)*ry(i+1) - ry(i)*rx(i+1); end

presumrec(1,Nb+1) = rx(Nb+1)*ry(1) - ry(Nb+1)*rx(1);

sumrec = (1/2)*sum(presumrec); //this is the area of the white region.

//75129 same with image

By implementing code 1, I was able to determine the area of the white region found in figure 1.
So long as the region of interest is convex(meaning no other cavities exists within the white region, code 1 can be a safe bet on computing for the area of the rectangle, or any shape for that matter. But (there is always a but) if the region is not convex or other cavities reside within the region of interest, code 1 is not useful at all.

Figure 2: Hollow rectangle. This is actually figure 1, but with a hollow center. We could treat it as a cavity inside the region of interest (white region).

Implementing the same code 1 on figure 2 yields the same area, 75129 pixel size squared, which, just by looking at figure 2 is very wrong. With this, I found at least 1 limitation of the algorithm.
So, as long as the region is convex, there is no problem!

As stated earlier, one of the applications of this activity is remote sensing or land estimation, so let's apply what we learned.

Figure 3: A map of the Mt. Apo park located in Davao City. This was taken from google maps.

In Figure 3, the green shade is our region of interest. By applying the Green's theorem, we may be able to determine the land area of the Mt. Apo park. The first thing I did was to convert this image into black and white, in order to delineate the edges of the region of interest from the background.

Figure 4: Black and White image of Mt. Apo. This image can now be used to determine the edges and then find the area of this contour (white region).

Using figure 4, we can now estimate the area of the Mt. Apo national park. Using the algorithm in code 1, the area of the white region is 73122.5 pixel size squared. The only thing we have to do next is to convert this pixel sized squared to kilometers squared. In order to do this, we have to relate pixel size to kilometers and figure 5 helps us do this.

Figure 5: Scaling factor. This scaling factor comes with figure 3. We will be using the 5 km scaling factor. By determining the number of pixels in 5 km, we can convert the area in terms of pixel size squared to kilometers squared. There are 66 pixels in 5 kilometers or 0.076 km/pixel

So now we have the area in terms of pixel size and the number of pixels in 1 kilometer. By mere dimensional analysis, the estimated land area of the Mt. Apo national park is 422.36 kilometer squared.

The next thing to do is to validate this area, compare it with the actual know area of the Mt. Apo national park. According to wikipilipinas, under the republic act 9237, the effective land area of Mt. Apo national park is 54974 hectares or 549.74 kilometer squared. This known area, compared with the estimated area gives us an error of 23.17%. This big of an error may have come from the fact that in area estimation, we are only working with an image, meaning only the 2D plane is considered and any elevation (consider this as the 3rd dimension) is neglected. The known area of 549.74 kilometers squared considers the elevation, the depression of the place, whereas in the estimated area of 422.36 kilometers squared, neither elevation nor depression is considered. This gives us another limitation when using the algorithm of area estimation.

With this activity, I learned yet another skill, and I know someday this will become very useful. So, for technical correctness, I'll give myself a grade of 5 for understanding the concepts behind area estimation. For quality of presentation, I'll also give myself a grade of 5 for presenting the images properly and with the right caption. All in all, 10 out of 10, it feels good. :)

2 comments: