# Semi-Global Stereo Matching Algorithm Based on Multi-Scale Information Fusion
## 2 SGM-MSIF Algorithm
### Disparity Computation and Disparity Optimization  
In this step, through the WTA strategy [27], the initial disparity map is obtained by selecting the disparity corresponding to the minimum cost value in \(\tilde{C}^{0}\). However, there are some occluded regions in the stereo pairs due to the position relationship between cameras, and the disparity of these regions is invalid. Therefore, the initial disparity map needs to be optimized.  
Left-right consistency check is a common algorithm for the detection of occluded regions and removal of mismatched pixels in stereo matching. The left and right disparity maps need to be obtained before the consistency check [28]. \(p=(u,v)\) is a pixel in the left image with disparity value of \(D_{p}\). \(q=(u-D_{p},v)\) represents the corresponding point of \(p\) in the right image and the disparity of pixel \(q\) is \(D_{q}\) according to the right disparity map. If \(D_{p}\) and \(D_{q}\) satisfy the condition:  
\[\left|D_{p}-D_{q}\right|\leq 1 \tag{18}\]  
Then pixel \(p\) passes the left and right consistency check and \(D_{p}\) is the effective disparity. Otherwise, pixel \(p\) will be regarded as the mismatched pixel, and its disparity value is invalid. It will be replaced by the minimum value of the two effective disparities located in the same row and closest to pixel \(p\).  
The efficiency of traditional left and right consistency check is low since two turns of cost calculations and cost aggregations are required to obtain the left and right disparity maps. When calculating the initial matching cost, for a pair of pixels, matching the right image through the left image and matching the left image through the right image are equivalent. Therefore, to further improve the processing efficiency of the algorithm, the internal left-right consistency check is used to optimize the disparity in this paper, that is,the right cost volume is calculated based on the left cost volume. The principle of the cost space conversion is shown in Figure 4, and its expression is:  
\[\hat{C}_{Right}((u,v),d)=\hat{C}_{Left}((u+d,v),d) \tag{19}\]  
where \(\hat{C}_{Right}\) and \(\hat{C}_{Left}\) represent the cost volumes of the right and left image with multi-scale information, respectively. \(\hat{C}_{Right}((u,v),d)\) and \(\hat{C}_{Left}((u+d,v),d)\) represent the cost values of pixels \((u,v)\) and \((u+d,v)\) under disparity \(d\), respectively. Since \(\hat{C}_{Left}\) is known, it is easy to obtain the cost volume of the right image through the conversion of Equation (19). Then we can get the left and right disparity map through the WTA principle. This process requires only one cost computation and one cost aggregation, which can improve the processing efficiency of the algorithm while ensuring the matching accuracy.  
Moreover, in order to better preserve the edge information, the weighted median filter with bilateral filter as the weight [29] is used to optimize the disparity map in the algorithm. The median filter [30] is adopted to remove the noise in the disparity map. Thus, we get the final refined disparity map and use it for the experimental analysis.