# Unsupervised Color-Based Flood Segmentation in UAV Imagery
## 3 Methodology
### Flood Dominant Color Estimation  
As described in Sections 3.2 and 3.3, five masks with potential non-flooded areas are constructed. There are cases where these masks describe approximately the same areas, but essentially the masks complement each other. When all masks are robust in classifying an area as non-flood, then the conclusion for this specific area is strengthened. But if one mask is weak in characterizing the area as non-flood, the other masks function as reinforcement. The final mask (\(M_{Final}\)) for the non-flood class is derived by combining these individual masks, as also depicted in Figure 3:  
\[M_{Final}=M_{RGBVI}\;\cup\;M_{L}\;\cup\;M_{A}\;\cup\;M_{B}\;\cup\;M_{Edge} \tag{3}\]  
The morphological operation of image closing follows, merging adjacent areas that are partially separated and connecting nearby regions. Excluding the non-flood labeled pixels of the final mask leaves us with potential flood areas, which, of course, have to be refined, as described below. We opt for a weighted approach to estimate the dominant color of the flood in the image. The rationale behind this approach is that we obtain a set of confidently non-flood areas through the union of five binary masks. All other regions in the image are designated as potential flood areas. Within these PFAs, the objective is to identify the dominant color of the flood for precise segmentation. The likelihood that a pixel belongs to a flood area increases with its distance from a non-flood area. Consequently, such pixels should have a greater influence on the estimation of the dominant color, achieved by assigning them a higher weight. Taking into account the non-flood area derived from \(M_{Final}\), the Euclidean distance transform [45] assigns to each potential flood pixel a value representing its distance to the nearest boundary pixel (non-flood). This representation of the spatial relationship between the pixels serves as a weight map (\(W\)), where the pixels farther away from non-flood areas receive greater weights such that their color (\(I_{C}\)) will exert a more significant influence on the process of the flood's dominant color estimation:  
\[W(p)= \begin{cases}\frac{||p-p^{\prime}||}{max_{\in PFA}||q-q^{\prime}||}&,\;\; \text{if $p\in\text{PFA}$}\\ 0,&\;\;\text{otherwise}\end{cases}  \tag{4}\]  
where \(||.||\) denotes the Euclidean norm, \(p\) is the pixel for which the weight value is calculated, and \(p^{\prime}\) is the nearest non-flood pixel to \(p\). Similarly, \(q^{\prime}\) is the nearest non-flood pixel to \(q\in PFA\). The denominator in Equation (4) is used for normalization purposes so that \(W(p)\leq 1\). The weighting variance (\(\sigma_{C}^{2}\)) for each color component (\(C\)) is calculated on the potential flood area (\(PFA\)) as follows:  
\[\sigma_{C}^{2}=\frac{N}{N-1}\cdot\frac{\sum_{p\in PFA}W(p)\cdot(I_{C}(p)-\mu_ {C})^{2}}{\sum_{p\in PFA}W(p)} \tag{5}\]  
where \(N\) and \(p\) are the total amount of potential flood area pixels and an image pixel, respectively. The mean color value of the potential flood for each component \(C\in L\), \(A\), \(B\) is represented by \(\mu_{C}\):  
\[\mu_{C}=\frac{\sum_{p\in PFA}W(p)\cdot I_{C}(p)}{\sum_{p\in PFA}W(p)} \tag{6}\]  
The estimated variance (\(\sigma_{C}^{2}\)) can be much higher than the real one, due to the fact that \(PFA\) may also contain non-flood pixels. Furthermore, the estimated \(\sigma_{C}^{2}\) in the PFA region should be much lower than the corresponding variance estimated in the entire image (\(\overline{\sigma_{C}^{2}}\)), due to the high color similarity between the flood pixels. So, \(\sigma_{C}^{2}\) is corrected to a predefined percentage (e.g., 20%) of \(\overline{\sigma_{C}^{2}}\) when it exceeds this value.