## 3 System Model
### Similarity Measurement  
Common similarity measurement methods based on local and global pixel-level descriptors often lead to misjudgments when dealing with scenarios where the appearance varies significantly at the same location or appears similar at different locations. To alleviate the aforementioned problem, this paper aims to leverage the spatial information of images to enhance the capability to handle variations in environmental appearance due to changes in lighting, weather, or seasons.  
Taking advantage of the natural properties of the CNN convolution process that overlap each convolutional sliding window, all the context information at the patch boundaries is preserved. Unlike SAES [35], the similarity matrix of MetricNet can be constructed without the loss of information, and the data distribution in the similarity matrix determines the final similarity score between two frames. We derive the feature descriptors based on patches and calculate a patch-by-patch similarity matrix. The feature maps refined by CWM are equally divided into four patches and then flattened to vectors for similarity calculation. The corresponding process for the patch feature descriptors is:  
\[F_{weight}^{p}=[f_{p0}\,f_{p1}\,f_{p2}\,f_{p3}]^{T},\ p\in\{1,2\} \tag{4}\]  
where \(p\) indexes the feature map pertinent to the paired input images \(\{I_{1},I_{2}\}\). \(f_{pi}\in R^{\frac{C\text{HW}}{4}\times 1}\) is the \(i\)-th feature patch vector of matrix \(F_{weight}^{p}\in R^{4\times\frac{C\text{HW}}{4}}\).  
Conventional approaches to similarity measurement typically employ a predetermined metric like Euclidean distance to gauge the resemblance between image pairs. In light of the efficacy demonstrated by our proposed methodology, we utilize the cosine similarity to appraise the similarity across all feature map patches within our Similarity Measurement Module (SMM). This procedure is delineated as follows:  
\[M_{ij}=\cos(f_{1i},f_{2j}) \tag{5}\]  
where \(M_{ij}\) is the calculated similarity corresponding to the patch descriptors \(f_{1i}\) and \(f_{2j}\). The higher the result, the greater the similarity between the feature patches. Briefly, the entire similarity matrix is the \(4\times 4\)-dimensional matrix calculated as follows:  
\[M=\begin{bmatrix}M_{00}&M_{01}&M_{02}&M_{03}\\ M_{10}&M_{11}&M_{12}&M_{13}\\ M_{20}&M_{21}&M_{22}&M_{23}\\ M_{30}&M_{31}&M_{32}&M_{33}\end{bmatrix} \tag{6}\]  
The similarity calculation based on the similarity matrix can be divided into two stages: constructing a \(4\times 4\) similarity matrix based on feature block mapping and obtaining the overall similarity from the similarity matrix. Figure 4 displays the block-based similarity matrix between two images of the same location in different seasons and two images of different locations, where grayscale values in the similarity matrix image represent the degree of similarity. Specifically, if the feature blocks are completely identical, the similarity is highest, indicated by the white color; otherwise, it is black. As shown in Figure 4d, the diagonal values are generally higher than those of the off-diagonal, whereas the values in Figure 4e show a clear difference. It means that the proposed SMM can effectively distinguish the positive and negative pairs.  
However, directly summing the diagonal values in the similarity matrix does not leverage this characteristic of data distribution. To distinguish between closed-loop pairs and non-closed-loop pairs based on the characteristics of data distribution and we normalize the element values of the similarity matrix between [0,1] and integrate the distribution pattern of the diagonal of the similarity matrix to define the overall similarity score \(S\) of the image pair as:  
\[S=\alpha\sum_{i=0}^{3}\omega_{i}M_{ii} \tag{7}\]  
where \(M_{ii}\) is the similarity value between two patches with the same index. \(\alpha\) represents the probability that the image pair comes from the same location, and \(\omega_{i}\) weights the diagonal elements. Detailed parameter settings are described below.