## 3 Methods
### Matching Cost Aggregation Based on Improved Adaptive Weight  
The size and shape of the support window must be determined first in the aggregation operation of matching cost. Since the general support window is a square window with a certain size, which contains all the pixels in the window, to reduce the operation time, this algorithm implements the improved census. The sparse support window is selected when the transformation and matching cost aggregation. The paper [27] compares the matching effect based on the sparse window and the ordinary window and proves the feasibility of the sparse window. The sparse window and the ordinary window are shown in Figure 1. If the window size is \((2n+1)\times(2n+1)\), the number of corresponding points in the common window is \((2n+1)\times(2n+1)\). However, the sparse window has only \((n+1)\times(n+1)+1\), which is about \(1/4\) of the normal window. When dealing with the problem of mismatching in edge regions, such as depth discontinuity, the matching cost aggregation method based on graph cuts can often achieve better results than adaptive weights. However, the matching accuracy corresponding to the method based on graph cuts depends heavily on the segmentation effect. In general, the cost of obtaining high matching accuracy is to enhance the robustness of the segmentation algorithm, and this operation also makes the overall complexity of the algorithm very high. That is, it is not suitable for occasions that require real-time performance. Basedon adaptive, the weight method is relatively stable and less complex than the graph cut algorithm, but its matching accuracy is lower than that of the graph cut method. To combine the advantages of graph cuts and adaptive weights, based on the adaptive weight method, we first use the color and distance similarity between the pixels in the support window and the center pixel to segment each pixel in the support window. If the pixel satisfies the set conditions, it is determined that it belongs to the same segmentation unit as the center point, and the maximum weight value \(1\) is assigned to it; if not, it is determined according to the color and distance similarity between the two pixels. Assigning weights, that is, the complexity of the improved adaptive weighting algorithm, remains unchanged. The rule for judging whether it belongs to the same division unit as the center point is shown in Equation (23). \[q\in S_{p}\Leftarrow\left\{ \begin{array}{cc}D_{c}(p,q)\leq c_{1}&D_{d}\leq d _{1}\\ D_{c}(p,q)\leq c_{2}&d_{1}<D_{d}\leq d_{2}\end{array} \right. \tag{23}\]  
where \(S_{p}\) is the corresponding segmentation units of the central pixel \(p\), \(D_{c}(p,q)\), and \(D_{d}(p,q)\) are the color difference and distance between the two points \(p,q\), as shown in Equation (24), \(c_{1},c_{2}\) are the threshold value of the set color difference, and \(c_{1}<c_{2};d_{1},d_{2}\) are the threshold value of the distance set. When the distance between two pixels is very close, a slightly loose range of color difference is used to judge whether the two pixels belong to the same segmentation unit as the center pixel. When the distance increases, the color threshold is reduced. It is considered that only when the color is very close can they be recognized as belonging to the same segmentation unit. When the distance is too large, it is considered that they do not belong to the same unit. \[ \begin{cases}D_{c}(p,q)=\sqrt{\left(R_{p}-R_{q}\right)^{2}+\left(G_{p}-G_{q} \right)^{2}+\left(B_{p}-B_{q}\right)^{2}}\\ D_{d}(p,q)=\sqrt{\left(u_{q}-u_{p}\right)^{2}+\left(v_{q}-v_{p}\right)^{2}} \end{cases}  \tag{24}\]  
According to the method, the weight distribution rules of each pixel in the support window can be obtained, as shown in Equation (25). \[w(p,q)= \begin{cases}1&,q\in S_{p}\\ exp(-D_{c}/\lambda_{c}-D_{d}/\lambda_{d}),&\text{\emph{other}}\end{cases}  \tag{25}\]  
Among them, \(\lambda_{c}\) and \(\lambda_{d}\) are color and distance factors, which are used to adjust the influence of color difference and distance on weight.