## 2 Materials and Methods
### Loop-Closure Detection
#### 2.4.1 Similarity Calculation  
The primary requirement for the first detection layer is high computational efficiency with a reasonable level of accuracy to filter out a coarse set of candidate frames. The feature distance will be calculated using the Manhattan distance, characterized by its low computational complexity, fast speed, and robustness against outliers, making it suitable for this purpose. The calculation formula is as follows:  
\[m=\sum_{i=1}^{n}\lvert\mathbf{v}_{1}[i]-\mathbf{v}_{2}[i]\rvert \tag{17}\]  
where \(\mathbf{v}_{1}\) and \(\mathbf{v}_{2}\) represent the aggregation feature descriptors of the current frame and the candidate frame, respectively, and \(n\) is the size of the descriptor.  
The second layer of detection involves more refined processing. We first assess the energy distribution of the current grayscale features to accommodate overly dark or bright image data. We uniformly divide the vector into three segments and calculate the energy proportion of the first and third segments. When this energy proportion \(p\) exceeds 95%, we have sufficient reason to consider the current image excessively dark or bright. We apply a weighting function to the features for such images, amplifying local differences. Inspired by Contrast Limited Adaptive Histogram Equalization (CLAHE), we perform energy proportion and weighting function calculations in each well-segmented small area to better preserve local information. We then use the correlation coefficient to calculate similarity. Although this computation is relatively complex, it offers superior discriminative performance.  
\[p=\frac{\sum_{i}^{n/3}\mathbf{v}[i]}{\sum_{i}^{n}\mathbf{v}[i]} \tag{18}\]  
The weighting function \(K\) is defined as follows and is represented in vector form as \(\mathbf{w}\):  
\[K(i)=\frac{k}{\sqrt{1+\left(\frac{i}{l_{0}}\right)^{2}}}=\mathbf{w}[i] \tag{19}\]  
Figure 5: Aggregation feature descriptor generation process. Each image generates two feature vectors, aggregated from the feature matrix along the row and column directions.  
The correlation coefficient for calculating similarity is as follows:  
\[r=\frac{\sum_{i=1}^{n}\left(\mathbf{v}_{1}[i]-\overline{\mathbf{v}_{1}}\right) \left(\mathbf{v}_{2}[i]-\overline{\mathbf{v}_{2}}\right)}{\sqrt{\sum_{i=1}^{n} \left(\mathbf{v}_{1}[i]-\overline{\mathbf{v}_{1}}\right)^{2}}{\sum_{i=1}^{n} \left(\mathbf{v}_{2}[i]-\overline{\mathbf{v}_{2}}\right)^{2}}} \tag{20}\]  
where, \(\overline{\mathbf{v}}\) denotes the mean of the descriptors, and the range of \(r\) is \([-1,1]\). The correlation coefficient reflects the linear relationship between features, making it suitable for feature selection [51]. In our work, we adopt the discrete form of the correlation coefficient. Unlike the Manhattan distance used in the first layer of detection, the correlation coefficient is dimensionless and unaffected by the units of feature vectors. This makes it particularly advantageous for calculating the similarity between two aggregated feature vectors with different units. Additionally, the correlation coefficient captures the directional differences between features rather than just absolute differences, offering higher-detail resolution and better adaptability to different scenes. Choosing the correlation coefficient for the similarity calculation in the second layer of detection is a more rational and robust design compared to conventional distance-based methods.  
Applying the weight vector to the similarity calculation, \(\mathbf{v}=\mathbf{w}^{\text{T}}*\mathbf{v}\), enhances the adaptability of the method.  
The luminance of an image inherently represents global information. These features must be handled carefully during the detection to preserve this information. Therefore, the weighted features should only be used to calculate similarity when the current frame and the frame under consideration are either excessively dark or bright.