Monday, September 5, 2016

Activity 4 - Length and Area Estimation in Images

Activity 4 is about estimating lengths and areas in images using image analysis softwares and a little bit of math. Here, we consider an important mathematical theorem -- Green's theorem. We follow the flow of the discussion in our activity manual (thank you ma'am for the discussion). Green's theorem considers any closed contour C which encloses an area R, functions X and Y, and relates a double integral to a line integral.




Essentially, if we choose functions that will somehow uncomplicate the math, we can end up relating the area enclosed by the contour and the circumference of the formed shape. To achieve this, we consider 2 cases: (1) X=0 and Y=x, and X=-y and Y=0. So we get the following 2 equations, where both of the left hand sides correspond to the area R. 


Considering these 2 equations, we average the 2 and we get an equation for the area.

Since we're dealing with a finite resolution, we consider the discrete form of this equation, and finally we have the following equation, where Nb is the number of pixels of the contour.

Now that we have discussed the theory, we move on to the activity itself. The first part of the activity was to create images of regular shapes like a circle and a square. Then, using these, Green's theorem was to be employed to measure the area enclosed by the shapes. Since I was able to pass activities 2 and 3 last Wednesday (August 24), I got the instructions for activity 4 and so I was able to work on it earlier than the scheduled class time for the activity. I started with creating an image of a square in bitmap format using Scilab (shape should be white and the remaining areas black). 


A 400x400 pixel white square
I then tried extracting the contour enclosing the shape using the edge function of the Scilab Image and Video Processing (SIVP) toolbox. However, I was able to get only dots and not really the edge of the shape. I temporarily let this pass and continued coding to sort the supposed edge to run in a clockwise manner and finally compute the area of the shape. 

Wednesday (August 31) came and it was the officially the start of activity 4. This time, I was able to successfully extract the edge of the square using the 'canny' method of edge extraction available in the edge function (thanks to Harold for the suggestion). I was able to calculate an area of 159997 pixels, which compares quite closely to the analytical area of 160000 pixels, deviating only by 0.0019% (essentially 0%!). I also tried doing this activity on a circle, which is shown below. I calculated an area of 384097 pixels, which also compares quite closely to the analytical area of 384845.1 pixels, deviating only by 0.19%.

A white circle with radius of 350 pix
Area estimation was also done on an area in Google map. Somehow, I decided to use Quezon City Memorial Circle as my location. Similar to the previous shapes, the area of interest was colored white and the other area was colored black. The same code used earlier was also employed (thanks to Carlo for helping in the calculation of the centroid of an arbitrary shape). Using Scilab, the area was calculated to be 218479.5 pixels. 


Screenshot of Quezon City Memorial Circle in Google map

Edited image where the area of interest was colored white and the remaining area was colored black
ImageJ software was used to relate the number pixels to the actual length by using the scale bar on the lower right of the map. It was found that the ratio is 0.865pix/m. Using this, the circumference of QC circle was traced and its area was measured to be 293251.4 m^2. We also use the pixel ratio to convert the calculated area (in pixels) to m^2, and we calculate an area of 291997.1 m^2. This has a difference of 1254.3 m^2. This is quite small compared to the order of magnitude of the measured area, but quite large when considering the value of the area itself. Note that measurement of the area in ImageJ involved tracing the circumference of the shape. Tracing was difficult using a trackpad of a laptop, and so the deviation may have been contributed upon by this, since the trace (yellow in color) was not perfectly on the circumference (refer to the image below).




We have seen how useful Green's theorem is in approximating areas (assuming a flat surface), along with image analysis softwares. Green's theorem more or less accurately approximates areas within closed contours. ImageJ (or other image analysis softwares) simplifies length and area approximation by setting a scale and just tracing the length or area of interest.

I would give myself a grade of 9 since I was able to obtain quite accurate results, except for the approximation of QC circle's area. Nonetheless, I have gained knowledge of the application of Green's theorem (one among a lot of concepts which I wondered where I would use when we were taking Mathematical Physics courses), and I have realized how powerful ImageJ is in image analysis (which I have used in the past only for putting scale bars in scanning electron microscopy images).


No comments:

Post a Comment