# Multi-Scale Flame Situation Detection Based on Pixel-Level Segmentation of Visual Images
## 3 Method
### The Framework of Flame-SeaFormer
#### 3.2.2 Static Flame Parameter Inversion of Individual Combustion Image  
Static parameter inversion focuses on deducing static flame parameters, including the flame height, width, and area, by analyzing flame edge information based on image segmentation results. Image contrast is omitted from this analysis due to its susceptibility to external factors such as lighting and shadows.  
Firstly, the coordinates of all non-zero elements are obtained from the binary mask image:  
\[S_{flame}=\{(a_{i},b_{i})\ |\ Mask(a_{i},b_{i})=1\} \tag{17}\]  
where \((a_{i},b_{i})\) is the position of the \(i\)-th non-zero element in the mask. Then, the coordinates are sorted in ascending order, with priority given to vertical coordinates. In the case of the same vertical coordinates, ascending order is applied to horizontal coordinates:  
\[S^{\prime}_{flame}=\text{sort}(S_{flame}). \tag{18}\]  
The sorted sequence of flame pixels is then used to extract the flame contour. Starting with the first point \((x_{1},y_{1})\) in \(S^{\prime}_{flame}\), it is considered the initial point on the flame contour and subsequently removed from the sequence. The remaining points are searched, and any point \((x_{j},y_{j})\) with \(x_{j}=x_{1}\) or \(y_{j}=y_{1}\) is added to the contour coordinate set and removed from the sequence. This process continues until the sequence is empty. The extraction of contour points is expressed as  
\[C^{\prime}_{flame}=\text{contour}(S^{\prime}_{flame},(x_{1},y_{1})) \tag{19}\]  
where contour represents the method of extracting contour points. \(C^{\prime}_{flame}\) denotes the initial flame contour coordinate set, which serves as the basis for the calculation of the subsequent flame width, height, and area.  
The contour \(C^{\prime}_{flame}\) from the fire segmentation results may not accurately fit the real contour of the flame. To address this, a fusion process is employed to enhance the accuracy of the flame height, width, and area values. Firstly, Canny edge detection is performed on the input image \(I\) to obtain the set of edge \(E_{flame}\):  
\[E_{flame}=\text{Canny}(I). \tag{20}\]  
For every pixel \(p\) in \(E_{flame}\), if it is near the pixels in \(C^{\prime}_{flame}\), it is added to \(C_{flame}\). The process is iterated continuously until the fused contour \(C_{flame}=\{(x_{1},y_{1}),(x_{2},y_{2}),\ldots,(x_{n},y_{n})\}\) is obtained, where \(n\) is the number of contour points.  
Based on \(C_{flame}\), the flame height, width, and area can be calculated. The height of a flame object is defined as the difference between the maximum and minimum values of the \(y\)-coordinates in the sequence of coordinate points along the flame's contour:  
\[H_{flame}=\max(Y)-\min(Y) \tag{21}\]  
where \(Y\) represents the set of \(y\)-coordinates of the flame contour points, max means to take the maximum value, and min means to take the minimum value. The width of a flame object is defined as the difference between the maximum and minimum values of the \(x\)-coordinates:  
\[W_{flame}=\max(X)-\min(X) \tag{22}\]  
where \(X\) means the set of \(x\)-coordinates of the flame contour points. Finally, the polygon area method is employed to obtain the flame area \(A_{flame}\):  
\[A_{flame}=\frac{1}{2}\sum_{i=1}^{n}[(x_{i}\times y_{i+1}-x_{i+1}\times y_{i})]. \tag{23}\]  
Through the fusion operation described above, more accurate static flame parameters are obtained.  
It is worth noting that in cases where the flame object in the image is fragmented or dispersed, multiple contour sequences may exist. In such a scenario, the calculation of their static parameters is carried out as follows:  
\[H_{flame}=\underset{i=1}{\max}(H_{flame}^{i}) \tag{24}\]  
\[W_{flame}=\sum_{i=1}^{d}(W_{flame}^{i}) \tag{25}\]  
\[A_{flame}=\sum_{i=1}^{d}(A_{flame}^{i}) \tag{26}\]  
where sum means summation, and \(d\) is the number of flame objects, which is equivalent to the number of contours.