# Spectra-Based Selective Searching for Hyperspectral Anomaly Detection
## 2 Materials and Methods
### Proposed Anomaly Detection Algorithm
#### 2.2.2 Region Merging  
By setting an appropriate segmentation parameter \(K\) and using a dynamic similarity criterion among the anomalous pixels and background pixels, the applicable oversegmentation of hyperspectral images is achieved via the graph-based image segmentation method. It is important to further coalesce the background regions so that anomaly pixels can be distinguished. The principle of region merging is that the background and anomaly regions are dissimilar. Therefore, the similarity computation between all neighboring regions is an important basis for judging whether the regions belong to the same class or object [44; 45; 46]. The average spectrum of all pixels in each region is utilized to represent the spectral characteristics of regions, thereby calculating the similarities of adjacent regions. Only the shape similarity of the regional mean spectrum is considered here, and the similarity is computed by the linear combination of the spectral angle and the correlation coefficient, given by  
\[simi=\left(1-\frac{sa}{\pi}\right)+\frac{(1+r)}{2} \tag{11}\]  
The value range of Equation (11) is from 0 to 2. The larger \(simi\) is, the more similar the two neighboring regions are, and the sooner the two regions will be merged into one region. The similarities of all pairs of initial neighboring regions are calculated and recorded in a similarity matrix. The greedy algorithm is used to iteratively merge the two adjacent regions with the highest similarity. A threshold \(T\) for constraining the degree of region consolidation is preset, whose range is determined by the minimum and the maximum of the similarity matrix. Then, the maximum value of the similarity matrix is extracted and compared with the threshold. When the maximum is larger than the threshold, the corresponding two contiguous regions are merged into a new region. The similarity values related to the two merged regions in the original similarity matrix are deleted. The similarity matrix is updated by computing the similarities between the new region and its neighboring regions. The regions stop merging until the iterative loop condition is not satisfied, that is, the maximum value in the similarity matrix is less than the threshold. Finally, those regions that fail to merge with most of the pixels in the image are anomalous targets to be detected. The flow of the proposed spectra-based selective searching algorithm is summarized in Algorithm 1.  
```
1. A hyperspectral image \(HSI\)
2. The parameter \(K\) for the creation of initial region
3. The threshold \(T\) for the region merging
4. A two-dimensional map recording the detection result \(Img\)-\(R\)
5. For the input hyperspectral image data \(HSI\)
6. Obtain initial region \(R=\{r_{1},\cdots,r_{n}\}\) using [PERSON] and Hutttenlocher (2004);
7. Initialise similarity set \(Simi=\varnothing\);
8. For each neighboring region pair \(\left(r_{i},r_{j}\right)\)do
9. Calculate similarity \(Simi\left(r_{i},r_{j}\right)\);
10. \(Simi=Simi\cup Simi\left(r_{i},r_{j}\right)\);
11. Get highest similarity max\(Simi=\max(Simi)=Simi\left(r_{i},r_{j}\right)\);
12. While max\(Simi\geq T\)do
13. Merge corresponding regions \(r_{t}=r_{i}\cup r_{j}\);
14. Remove similarities regarding \(r_{i}:Simi=Simi\backslash Simi(r_{i},r^{*})\);
15. Remove similarities regarding \(r_{j}:Simi=Simi\backslash Simi\left(r_{j},r^{*}\right)\);
16. Calculating similarity Smit between region \(r_{t}\) and its neighbors;
17. Update similarity set \(Simi:Simi=Simi\cup Simi\);
18. Update highest similarity max\(Simi=\max(Simi)=Simi\left(r_{i},r_{j}\right)\);
```  
**Algorithm 1**Spectra-based Selective Searching for Anomaly Detection