## 3 Methods
### Matching Cost Calculation Method  
The calculation of matching cost is the first step of stereo matching operation, and its calculation method directly affects the accuracy of matching results and the complexity of the matching algorithm. The SAD algorithm is based on the difference of pixel gray values. It assumes that the gray values of the same feature point in the two images are the same, and the matching accuracy is directly related to the size of the support window. Its advantage is that the calculation is simple and fast, and it can obtain dense disparity images. However, it is difficult to complete the correct matching for large areas without texture or weak texture, and it is difficult to complete the correct matching for large areas without texture or weak texture. Shadows and noise are very sensitive. The structure of the census algorithm is relatively simple, the amount of calculation is small, and it can also obtain dense disparity images. The calculation result is only related to the comparison between the intensity values of gray pixel values. Therefore, it has suitable robustness and can effectively avoid the influence of radiation distortion and halo. However, it is easy to produce false matching in texture repetition or similar areas, and the matching performance will be reduced. To combine the advantages of the two algorithms and reduce the mismatching when the two algorithms are used alone, a weighted fusion of the matching cost calculation methods of the two matching algorithms is carried out in this paper to obtain a new matching cost calculation method. The SAD algorithm uses the sum of absolute values of the difference of gray values of all pixels in the support window as its matching cost. Considering that the existing imageis generally a color image, to make full use of the information contained in the color image, the sum of the absolute values of the difference between the gray values of the three-color channels of the color image is used as the matching cost of two pixels. Then, the two points' corresponding matching cost in the left and right image support Windows is shown in Equation (3). \[C_{AD}(p,d)=\sum_{c\in\{r,g,b\}}|I_{l}^{c}(p)-I_{r}^{c}(p-d)| \tag{3}\]  
Among them, the gray similarity between the two pixels corresponding to the value \(C_{AD}(p,d)\), \(I_{l}^{c}(p)\) and \(I_{r}^{c}(p-d)\), respectively, represents the gray value of the pixel in the left image and the corresponding pixel in the right image on the color channel \(c(c\in\{r,g,b\})\), which refers to the visual difference. Noise is an inevitable attribute when a camera acquires an image. It is a point with a jump in the intensity value compared with the surrounding area, so it will lead to a high matching cost. To reduce its adverse effects, truncated absolute differences (TAD) are introduced here, as shown in Equation (4). \[C_{AD}^{\prime}(p,d)=\min\{T_{c},C_{AD}(p,d)\} \tag{4}\]  
where \(T_{c}\) is the set truncation absolute error value. The census algorithm is a non-parametric transformation method that transforms the pixels in the matching window according to the transformation rules. The size relationship between the gray value of the center pixel of the window and the neighboring pixels in the window is transformed into a continuous bit string. The Hamming distance of the bit string of the corresponding block in the left and right images is used to measure the matching degree. The smaller the distance, the higher the matching degree. However, the basic census method is used for the gray image. To make full use of the information contained in the color image, the color distance between the neighborhood pixel and the center pixel in the matching window is used as a reference. To reduce the algorithm's complexity, the Manhattan distance is selected as the color distance, as shown in Equation (5).