Activity 4: Measuring Area from Images

đź•‘06:25, 20 Aug 2019

For this activity, I generated the basic shapes using the Python Imaging Library (PIL). This let me define the centroid and pseudo-radius (distance from the centroid to the midpoint of an edge) for each shape analytically, and therefore, I know precisely what their dimensions and areas will be. The shapes are shown in Fig. 1, all with size 1024x1024.

circle
circle
square
square
trapezoid
trapezoid
triangle
triangle

Figure 1: Basic binary shapes generated using the Python PIL library.

For extracting the edges of the shapes, I explored a few edge detection algorithms, eventually settling with the following:

From the traced edges, the area it encloses can be calculated using a discretized form of Green’s theorem [6]

where x_i, y_i are the pixel coordinates, and N is the number of pixels on the boundary. The results for each algorithm, along with their relative errors, are shown in Table 1, and the edge-traced images are shown in Figs. 2-5.

spot
spot
Sobel
Sobel
Prewitt
Prewitt
Laplacian
Laplacian
Canny
Canny

Figure 2: Edges extracted from the circle using different algorithms.

spot
spot
Sobel
Sobel
Prewitt
Prewitt
Laplacian
Laplacian
Canny
Canny

Figure 3: Edges extracted from the square using different algorithms.

spot
spot
Sobel
Sobel
Prewitt
Prewitt
Laplacian
Laplacian
Canny
Canny

Figure 4: Edges extracted from the trapezoid using different algorithms.

spot
spot
Sobel
Sobel
Prewitt
Prewitt
Laplacian
Laplacian
Canny
Canny

Figure 5: Edges extracted from the triangle using different algorithms.

Notice how the Sobel & Prewitt filters perform very similarly because they are both gradient-based methods. Due to their directional dependence, we can notice how the edges, particularly on the lower-right portions, are not being detected very well. Upon closer examination, however, the edges are being detected but are very faint (low magnitude). Spot and Canny, on the other hand, produce very clean and accurate edges. Laplacian also detects a clean edge but is somewhat low in magnitude.

Table 1: Actual and calculated areas (px2) of each shape and their corresponding relative errors. The percentages in bold indicate the best-performing algorithm for each shape.

ShapeActualspotSobelPrewittLaplacianCanny
circle502,655501,584503,187503,187503,198503,182
0.21%0.11%0.11%0.11%0.10%
square640,000639,800641,404641,404641,416641,398
0.03%0.22%0.22%0.22%0.22%
trapezoid426,667426,399428,002428,002428,013427,731
0.06%0.31%0.31%0.32%0.25%
triangle320,000319,102320,705320,705320,714320,304
0.28%0.22%0.22%0.22%0.09%

I chose the CS Amphitheater as a location of interest for calculating the area on a map. I obtained its actual area using Google Earth’s Ruler tool, then proceeded to import it into Photoshop. I then applied enough threshold so that the yellow line was clear and isolated from the other white spots. I manually erased any remaining white artifacts until only the circle and the line indicating the radius were left. I then measured the length of the radius in pixels, this time using Photoshop’s Ruler tool. Since the actual radius in meters was also provided by Google Earth’s Ruler tool, I was able to formulate the pixel-to-meter conversion as

Via Green’s theorem, I was able to obtain the Amphitheater’s area in pixels. However, this cannot be converted directly to real units using (6) because our current units are area, while the conversion equation only works for units of length. Since the amphitheater appears fairly circular, I used the formula for the area of a circle A = \pi r^2 and solved for r. I can now plug in this r directly into (6) and finally, multiply it again by \pi r to get the area in real units. The calculated areas for the different algorithms are shown in Table 2, and the edge-traced images are shown in Fig. 6.

Table 2: Actual and calculated areas (px2) of each shape and their corresponding relative errors. The percentages in bold indicate the best-performing algorithm for each shape.

actualspotsobelprewittlaplaciancanny
4485.924600.444630.524630.554629.644634.90
2.55%3.22%3.22%3.20%3.32%
Enclosed area in Google Earth
Enclosed area in Google Earth
Applying threshold and isolating the ROI
Applying threshold and isolating the ROI
spot
spot
Sobel/Prewitt
Sobel/Prewitt
Laplacian
Laplacian
Canny
Canny

We can observe that in general, the spot filter works best in edge detection. Upon further investigation, I found out that the spot kernel is actually a variant of the Laplacian kernel and produces exceptional results on arbitrary images.

References

  1. wiredfool, A. Clark, Hugo, A. Murray, A. Karpinsky, C. Gohlke, B. Crowell, D. Schmidt, A. Houghton, and S. Johnson, Pillow: The friendly PIL fork (2016).

  2. I. Sobel, An isotropic 3x3 image gradient operator, Presentation at Stanford A.I. Project 1968 (2014).

  3. J. M. S. Prewitt, Object enhancement and extraction, Picture processing and psychopictorics (1970).

  4. N. Tsankashvili, Comparing edge detection methods (2018).

  5. J. F. Canny, A computational approach to edge detection, IEEE transactions on pattern analysis and machine intelligence 8, 679 (1986).

  6. M. N. Soriano, Measuring area from images (2019).

Keywords

image processing
measuring area
edge detection
image filter
green's theorem
google earth