In this activity, our goal is to measure the areas and lengths in images using the Green’s function and the ImageJ application.
First, we consider three synthetic images of regular polygons in monochromatic bmp format
Figure 1. Basic shapes used. |
Using Scilab, we employ different edge detection techniques: a)Sobel b)Prewitt c)fftderiv d)Log e)Canny
Technique description:
Sobel:
The method [1] uses \(3 \times 3\) matrices that are convolved with the original image to compute for the derivative. The approximations \(G_x\) and \(G_y\) can be obtained from the original image \(Img\) via [2]:
\[\begin{equation} \label{eqn:gx} G_x = \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \\ \end{bmatrix} * Img \end{equation} \]
\[\begin{equation} \label{eqn:gy} G_y = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ +1 & +2 & +1 \\ \end{bmatrix} * Img \end{equation} \]
where the * denotes the convolution operator. Note that we can write the \(3 \times 3\) matrix used in \(G_x\) as
\[\begin{equation} \label{eqn:gxm} \begin{bmatrix} 1 \\ 2 \\ 1 \end{bmatrix} \begin{bmatrix} -1 & 0 & 1 \end{bmatrix} \end{equation} \]
wherein the individual vectors represent averaging and differentiation processes, respectively. Edge detection can be done by combining the effect of the rightward gradient from \(G_x\) and the downward gradient from \(G_y\),
\[\begin{equation} \label{eqn:sobelint} G = \sqrt{G_x^2 + G_y^2} \end{equation} \]
Prewitt:
The Prewitt operator [3] works as the Sobel operator, but with a different kernel. In particular, we only need to change the averaging vector in Eqn \(\ref{eqn:gxm}\) by:
\[\begin{equation} \label{eqn:gxmprewitt} \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} \begin{bmatrix} -1 & 0 & 1 \end{bmatrix} \end{equation} \]
FFTDERIV:
The method is based on the fact that the spatial frequencies are highest at locations in the images where there are sharp gradients, i.e. the edges. The method first detects these locations in the images via a fast Fourier transform (FFT) algorithm, and then convolves it back to the image, resulting in the preservation of only the edges of the image.
Laplacian of the Gaussian (LoG):
The image is first convolved by a gaussian kernel,
\[\begin{equation} \label{eqn:log} g(x,y,t) = \frac{1}{2\pi t^2}\exp\left(-\frac{x^2 + y^2}{2t^2}\right) \end{equation} \]
and then, afterwards, the change is detected via the discrete Laplacian operator \(\nabla^2 L\). This process detects the edges because this is where the Laplacian operator will show the most change.
Canny:
The Canny algorithm [4] is based on an initial convolution with a gaussian filter (as in LoG), but additional steps are used to thin the detected edges.
Below are images of the edges obtained using different techniques for the different polygons.
Figure 2. The synthetic shapes and the obtained edges using the different techniques.(L-R) a)Sobel b) Prewitt c)Log d)Fftderiv e) Canny |
As seen in Fig.2, the different edge-detection techniques were applied on the three polygons where the Sobel method (first from left) failed to capture the entirety of the shape edges especially along the horizontal and vertical orientation. It however recovered the pixels along the diagonal direction. On the other hand, the results of the Prewitt method and the Fftderiv method look similar to each other recovering the edges along any orientation. Among the methods, the Log method gave the clearest edges and this is due to its algorithm of convolving the image with a gaussian bell. Lastly, as seen, Canny also recovered all the edges but its width is noticeably thinner. This is due to its algorithm which includes an additional thinning process.
Green’s function relates the magnitude of the bounded area with the length of its closed bounding curve.
\[\begin{equation} \label{eqn:} A = \frac{1}{2}\oint\left(xdy - ydx\right) \end{equation} \]
The coordinates of each edge pixel is determined using the function \(\textbf{find ()}\). Using these x and y coordinates, we determine its angle with respect to the image centroid defined as \( centroid_i = \frac{sum(i)}{length(i)}\) in order to provide a directionality for the contour. We computed this angle using \(\theta = atan(\frac{y}{x})\).
After determining the angle, we sort them in increasing order with their corresponding x and y coordinates.
Below is my code for the Green’s function to compute for the area of the polygons and the subsequent irregular pattern(s) I used in the experiment. In the process of writing my code, I have received help from a lot of people: Roland Romero and Jan Zoluaga for helping me install SIP and SIVP in my Scilab version; Niña Zambale for teaching me the function \(\textbf(size())\) in Scilab which helped me solve my problem in my indexing and my \(\textbf(for loop)\) part; and Carlo Solibet for telling me that there is no need to place a \(\textbf(sum()\) function within my loop since the for loop already takes care of it and also for teaching me the function \(\textbf(disp()\) which is the counterpart of \(print\) in Scilab.
Figure 3. Code for Green's Function |
Table 1 summarizes the acquired area values for each polygon using different edge detection techniques.
As seen, the Sobel method has the highest percent error in calculating the area for all the shapes: ~24.32%, ~2.43% and ~49.13% respectively. This is due to the fact that it fails to recognize the edges completely. In contrast to the Log method which gave the least error for all which further confirms that the sharp detection of edges is the main contributing factor to the area computation. We also notice similar results for the Prewitt and Fftderiv methods which gives us a quantitative confirmation that both methods give the same result as seen earlier in Figure 2. Canny method in addition, also gave a considerably small error. The more important point here is that, the choice of edge-detection technique is dependent on the aim of the task at hand. One must recognize how much error one can tolerate in his computation.
Now that I have acquired a basic understanding of the underlying concept and the corresponding skill, I applied them to a more practical application. I chose the National Institute Physics as my test object. Using Google’s \(\textit{My Maps}\) which I learned from Zheinna Ottong, I was able to measure the area by tracing around its boundaries. The uncertainty of the area measurement is dependent on how well I’ve traced the perimeter of the building. I acquired an area of \(0.587 ha\) or \(5870 m^2\).
Figure 4.a)Image of the NIP building from Google maps with 10-m scale b) Bitmap image of NIP |
To verify, I converted the acquired area value of the NIP into \(px^2\) unit since the unit of the value obtained by the Green’s Function is also in \(px^2\). Using paint, I obtained the number of pixels equivalent to the \(10-m\) scale bar of Google found in the lower right of the image as seen in Fig.().
Figure 5. NIP building bitmap images and edges obtained using a)Sobel b) Prewitt c)Log d) Fftderiv e) Canny |
To rescale, I did the following conversion:
\[\begin{equation} \label{eqn:conversion} 0.587 ha * \frac{10 000 m^2}{1 ha} * \left(\frac{60 pixels}{10 m}\right)^2\end{equation}\]
We can see this modification in the latter part of my code:
Figure 6. Part of Code where I rescaled the theoretical area. |
Table 2 shows the area computation for the National Institute of Physics using the same techniques employed earlier.
As seen in Table 2, it is not the Log method that gave the least error. This confirms the fact that, the propriety of a method is dependent on the task. This time, the Canny method helped in getting the most accurate area computation for the National Institute of Physics.
For the second part of this activity,we were asked to scan our IDs. I opened the scanned the image of my ID using ImageJ, a free image processing software. First, we were asked to draw a line across the length of the ID. ImageJ spits out the length value in pixels. I also measured the length of my ID using a ruler and acquired a known distance of \(8.6 cm\). I used this value to calibrate ImageJ such that any subsequent measurements are now in real units (Fig.6).
Figure 7. Snapshot of my ID and ImageJ calibration |
Table 3 and Figure 6 show a summary and a schematic diagram of these measurement and their corresponding uncertainty.
Figure 8. Random Measurements taken |
From the results, the deviation in the measurements is due to the resolution of the measuring device. For instance, ImageJ uses the number of pixels for a given length so that it gives very precise measurements (evident in the following decimal figures) when converted in real units. But more or less, ImageJ (and the skills I learned earlier in the course i.e. scaling) is quite a useful tool when it comes to measuring things that are impossible to personally measure i.e. length of roads, area of land patches produced by the criss-crossings of these roads.
References:
[1] M. Soriano, 2016, Estimating Areas and Lengths in Images, Activity 4, AP186.
[2] Irwin Sobel, 2014, History and Definition of the Sobel Operator
[3] http://homepages.inf.ed.ac.uk/rbf/HIPR2/sobel.htm
[4] J.M.S. Prewitt "Object Enhancement and Extraction" in "Picture processing and Psychopictorics", Academic Press,1970
[5] Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8(6):679–698, 1986.
No comments:
Post a Comment