# Cavity Detection in Steel-Pipe Culverts Using Infrared Thermography +
## 4 Method
### A Statistical Method for Cavity Identification  
In this section, we describe a statistical approach allowing the detection of cavities in a thermal image sequence. Based on the theory described in the previous sections and using the cavity properties, we can conclude that a cavity can be identified by performing an analysis of abnormal fluctuations in temperature flow. At each frame (or time), we define an abnormal fluctuation as a temperature that is sufficiently lower or higher than the average. This assumption is made because under normal condition (no defects or cavities) the temperatures of different points on the specimen surface are very close. There are some variations due to noise, inhomogeneity of the reflections, and the impact of surface features, but these variations are usually negligible in comparison with those caused by a defect. From a statistical point of view, abnormal temperatures can be expressed as  
\[\mathcal{T}_{ab}=\{T|T\leq\mu-c_{1}\sigma\;\vee\;T\geq\mu+c_{1}\sigma\}, \tag{11}\]  
where \(\mu\) and \(\sigma\) are mean and standard deviation of the image and \(c_{1}\) is a constant coefficient. An analysis of the temperature distribution at a given time allows the image pixels to be classified into normal (0) or abnormal (1) classes. However, this approach is not sufficient to determine whether a pixel actually represents a cavity, as measurements are made at each individual moment. To account for all times (or frames), we use the idea of frequentist probability. This method allows the frequency probability of an event to be inferred using a large test set, considering each thermal image as a test. Now, we assign a probabilistic measure, indicating the likelihood of being a defect, to each pixel with the following expression  
\[P(x,y)=\frac{n_{1}(x,y)}{n_{t}},\text{ for }n_{t}\gg 1 \tag{12}\]  
in which \(P(x,y)\) is the probability of a pixel \((x,y)\) being a defect, \(n_{1}(x,y)\) is the number of times that pixel \((x,y)\) is classified as the defect category, and \(n_{t}\) is the total number of images in the given sequence. A limit of this equation is that it treats all temperatures larger than \(\mu+c_{1}\sigma\) or smaller than \(\mu-c_{1}\sigma\) similarly. However, in some cases we may need to look for temperatures within a range; similar to the idea of band pass filtering. This can be obtained by introducing terms \(n_{2}(x,y)\) and \(pen\) into the equation  
\[P(x,y)=\frac{n_{1}(x,y)-n_{2}(x,y)pen}{n_{t}},\text{ for }n_{t}\gg 1 \tag{13}\]  
where \(n_{2}(x,y)\) is defined like \(n_{1}(x,y)\), except that \(c_{1}\) is replaced with \(c_{2}\), and \(pen\) is a penalty factor from 0 to 1. When the penalty factor is 0, the expression is reduced to Equation (12). The main steps of this approach are given in Algorithm 1. With the help of coefficients \(c_{1}\) and \(c_{2}\) which are determined empirically, the equation can be adjusted for each experiment. ```
Data: \(pen\longleftarrow\) set the penalty coefficient; \(pen\in[0,1]\) \(c_{1},c_{2}\longleftarrow\) set \(c_{1}\) and \(c_{2};c_{2}>c_{1}>0\) Result:\(probMask\)\(data\longleftarrow\) get thermal image sequence (*.mat file) \(wFrm\), \(hFrm\), \(nFrm\) \(\longleftarrow\) get data dimensions \(freqMask1\), \(freqMask2\longleftarrow\) initialize to zero; array of size \(hFrm\times wFrm\) for\(k=1\)to\(nFrm\)do \(I\longleftarrow\)data(\(.;.