# Semi-Global Stereo Matching Algorithm Based on Multi-Scale Information Fusion
## 2 SGM-MSIF Algorithm
### Matching Cost Computation  
In this step, after obtaining stereo pairs at different scales [23], the best-matched point needs to be found for every pixel within the disparity searching range. The initial matching cost is used to measure the similarity of the corresponding pixels under different disparities. The traditional census transform [24] (based on the relative brightness difference in the window) can well process the inconsistent brightness of the stereo pair, and has certain robustness to the noise of the images. However, it is prone to produce ambiguity when dealing with repetitive texture regions. The cost computation method based on the absolute value of color difference in a single pixel [25] can reduce the ambiguity of repeated texture to a certain extent. It can quickly calculate the color difference of pixels in the left and right images. Therefore, in this paper, census transform method and color information are combined to obtain the initial matching cost, so as to make up for the defects of the traditional census method in the repeated texture regions.  
In the traditional census transform, the grayscale difference between the target pixel to be matched and its neighboring pixels needs to be calculated first. Then the grayscale difference is converted into a bit string. The matching cost is obtained by calculating the Hamming distance between the bit strings. The principle of census transform is shown in Figure 2. In this figure, _Left_ and _Right_ represent the stereo pair, \(u\) and \(v\) represent columns and rows of pixels, respectively and \(d\) represents the disparity. Firstly, the gray values of the pixels in the neighborhood window are compared with the gray value of the central pixel. It is counted as 0 if the gray value is larger than that of the central pixel and it is counted as 1 in other cases. The obtained 0 or 1 is mapped to a bit string in turn, and the bit string is the census transform result of the central pixel. Then the Hamming distance between the two pixels within the disparity search range is calculated and denoted as \(C_{cen}(p,d)\), which represents the census value of the pixel \(p=(u,v)\) under the disparity \(d\). In this way, the census initial matching cost volume \(C_{cen}\) with dimension \(W\times H\times L\) can be obtained, where \(W,H\) and \(L\) represent the width, height and disparity range of the image, respectively.  
Figure 1: The flowchart of SGM-MSIF algorithm.  
For the matching cost calculation based on color information, the average value of the difference among the three color components of the left and right image pixels is taken as the cost value to calculate the initial cost volume \(C_{cor}\), which is expressed as:  
\[C_{cor}(p,d)=\frac{1}{3}\sum_{k=R,G,B}\left|I_{k}^{Left}(p)-I_{k}^{Right}(q)\right| \tag{1}\]  
where \(p=(u,v)\) represents a pixel to be matched in the left image. \(q=(u-d,v)\) represents the corresponding search point of \(p\) in the right image. \(I\) represents the color component. \(C_{cor}(p,d)\) is the cost value of \(p\) obtained by using the average value of the color difference in disparity \(d\).  
Since the ranges of the above two matching cost values \(C_{con}(p,d)\) and \(C_{cor}(p,d)\) are different, normalization is required before combining the two methods. The normalization expression is shown in Equation (2):  
\[\rho(C,\lambda)=1-\exp(-\frac{C}{\lambda}) \tag{2}\]  
where \(\rho\) represents the normalized matching cost value. \(C\) and \(\lambda\) represent the matching cost values and normalized parameters corresponding to different methods, respectively. The initial matching cost after combination can be defined as:  
\[C(p,d)=\rho(C_{con}(p,d),\lambda_{con})+\rho(C_{cor}(p,d),\lambda_{cor}) \tag{3}\]  
where \(\lambda_{con}\) and \(\lambda_{cor}\) are the normalized parameters of \(C_{con}(p,d)\) and \(C_{cor}(p,d)\), respectively.