## 3 Methods
### Parallax Calculation and Post-Processing  
After the aggregation calculation of the matching cost, the disparity value corresponding to the minimum matching cost is selected as the disparity value of the corresponding pixel according to the WTA principle, as shown in Equation (12).  
\[d_{p}=argminE(p,d),d\in D \tag{12}\]  
\(D\) is the set of all parallax values within the allowable parallax range.  
In the disparity map based on the WTA principle, there are some mismatching points. To eliminate these mismatches, the left-right consistency constraint is used to detect the resulting disparity map. In stereo matching, when the left image is taken as the reference image, a point p 'is searched in the right image as the midpoint of the left image. If the right image is used as the reference image, the matching point of \"Midpoint\" in the left image must be a point; if not, it is an error-matching point.  
The left-right consistency constraint is shown in Equation (13). The left-right consistency detection is to use the obtained initial disparity map with the left and right images as the reference image to determine whether the disparity values of the corresponding matching points in the left and right images are equal. If they are equal, they are considered correct matching points. If they are not equal, they are identified as wrong matching points, and their parallax values are determined to be invalid so that their parallax values are 0.  
\[dl(p)=dr(p-(dl(p))) \tag{13}\]  
where \(dl(p),dr(p-(dl(p)))\) is the parallax values of the midpoint \(p\) of the left and the midpoint \(p-(dl(p))\) of the right image, respectively.  
For the detected mismatching points, if the difference between the left and right pixels is effective and close to each other, if it does not meet this condition, that is, it is not a single mismatching point, and the corresponding image is taken as the reference image. For the point with an effective disparity value in the window, according to the gray level and distance between the pixels in the window and the central pixel, the disparity value of the point in the window can be directly replaced by the average value of the disparity value. For the mismatched points in the window, the weight is 0, and the average value of the weight disparity value of all points in the window is used to replace the disparity value of the current point, as shown in Equation (14).  
\[d_{p}=\frac{\sum_{q\in N_{p}}w_{q}d_{q}}{\sum_{q\in N_{p}}w_{q}} \tag{14}\]  
Among them, \(d_{p}\) is the new disparity value of non-single mismatched point \(P\), \(N_{p}\) is the set of all pixels in the window, \(w_{q}\) and \(d_{q}\) are the weight value and disparity value of point \(q\), respectively.  
Because the parallax obtained in the matching process is an integer, and the matching point of the actual left image in the right image is almost impossible to fall on a complete pixel in the right image, that is, the phenomenon of precision loss exists in the previous matching operation. To reduce the precision loss, the parallax image is refined by the sub-pixel enhancement method to obtain sub-pixel precision. The interpolation Equation of the parallax image is shown in Equation (15).  
\[d^{\prime}=d+\frac{E(p,d_{-})-E(p,d_{+})}{2(2E(p,d)-E(p,d_{-})-E(p,d_{+}))} \tag{15}\]  
Among them, \(E(p,d_{-})\), \(E(p,d)\), \(E(p,d_{+})\) represent the matching cost of point \(p\) when the parallax is \(d-1\), \(d\), and \(d+1\), respectively, \(d^{\prime}\) is the Subpixel-precision disparity value obtained after interpolation. Finally, median filtering is used to smooth the obtained refined disparity map to eliminate possible noise points.