# Spatial and Channel Similarity-Aware Attention-Enhanced Network for Object Counting
## 3 Materials and Methods
### Spatial Similarity-Aware Module
#### 3.3.1 Similarity Feature Extraction  
First, the support feature \(f_{S}\in\mathbf{R}^{K\times C\times H_{S}\times W_{S}}\) and the query feature \(f_{Q}\in\mathbf{R}^{C\times H_{Q}\times W_{Q}}\) are individually processed through layer normalization. Then, they are projected into the comparison space using \(1\times 1\) convolution operations. It should be noted that the application of \(1\times 1\) convolutions ensures that the dimension of the feature unchanged, which not only helps to integrate information from different channels to enhance the capability of feature representation, but also makes the distribution of features uniform, thus improving the effectiveness of similarity calculations. In the comparison space, the \(f_{S}\) serves as the convolution kernel, and the \(f_{Q}\) undergoes slicing convolution operations in multiple directions to generate a score map. It is important to note that, due to the structured dimensionality of the input features, this convolution operation does not produce a scalar output. Instead, it generates a score map with a specific dimensional structure determined by the input feature dimensions and convolution rules. Next, the generated score map undergoes a normalization process to obtain the similarity map. Compared to the SAFECount, this method sequentially performs layer-by-layer convolutions on the query features in the following order: top-to-bottom (down), bottom-to-top (up), right-to-left (right), and left-to-right (left). In this way, the model is able to understand the different features of an object from various positions, thereby enhancing its ability to perceive complex scenes. Taking the down direction as an example, the input feature is sliced along the height (\(H\)) dimension, producing \(H_{D}\) slices, each of which is \(C\times W_{Q}\) in size. In traditional convolution, the output from each layer is directly passed to the next layer. However, the proposed method differs in that the convolution output of the current slice is added to the next slice, forming a new slice. Here, the convolution output is not a scalar but rather feature data with the same dimensional structure as the slice, and the addition operation is performed on features of the same dimensions. The newly formed slice is then further processed through convolution, and this iterative process is repeated until all slices are processed. Before the convolution results are passed to the next layer, a nonlinear activation function is applied. This multi-angle extraction method simulates the process of the human eye continuously changing its viewpoint while observing an object. It helps enhance the model's comprehensive understanding of object features and improves its ability to recognize complex object structures, addressing the limitations of traditional feature extraction methods that rely on a single viewpoint. The detailed process is precisely described in Equation (1). \[D_{H}^{i}=D_{H}(D_{H}^{i-1}+h_{D}^{i}) \tag{1}\]  
where \(D_{H}(*)\) denotes the operation applied to segments along the \(H\) direction. \(h_{D}^{i}\) represents the \(i\)-th segment along the \(H\) direction in the down layer. Similar procedures are executed for the remaining three directions, with operations performed sequentially in each direction. The resulting features then undergo simple NL and Conv processing to yield the score map \(M_{\text{SC}}\), as shown in Equation (2). \[M_{\text{SC}}=\sum_{i=1}^{4}\sum_{j=1}^{n}NL(Conv2d(D_{j},kernel=Conv_{1\times 1 }(f_{S}))) \tag{2}\]  
Here, \(NL(*)\) represents layer normalization, \(Conv2d(*)\) represents two-dimensional convolution, and \(Conv_{1\times 1}(*)\) represents \(1\times 1\) convolution. Subsequently, the score map \(M_{\text{SC}}\) is subjected to parallel sample normalization and spatial normalization. The outcomes of both normalizations are then subjected to the dot product \(\otimes\) to derive the similarity map \(M_{\text{N}}\in\mathbf{R}^{K\times 1\times H_{\text{Q}}\times W_{\text{Q}}}\). The specific procedure is described below.