# Simplified High-Performance Cost Aggregation for Stereo Matching
## 2 Methods  
### Traditional Local and Non-Local Stereo Matching Algorithms  
In this section, we examine two representative stereo matching algorithms proposed in [9; 17], which are classified as local and non-local, respectively. Traditional local and non-local stereo matching algorithms start with calculating a primary matching cost that reflects the degree of match between corresponding pixels on an image pair. Many measurements can be used for computing the primary matching cost. The implementation presented in this paper uses a linear combination of the truncated absolute difference of the gradient, denoted as \(\mathbf{C}_{TGD}\), and the Hamming distance of the census transform:  
\[ \begin{split}&\mathbf{C}_{TGD}(q,d)=\min(|\
abla_{x}\mathbf{I}_{L}(q)- \
abla_{x}\mathbf{I}_{R}(q+d)|,2)+\min(|\
abla_{y}\mathbf{J}_{L}(q)-\
abla_{y}\mathbf{I}_{ R}(q+d)|,2)\\ &\mathbf{C}_{Census}(q,d)=\text{Ham}(T_{Census}(\mathbf{I}_{L}(q)),T_{ Census}(\mathbf{I}_{R}(q+d))),\end{split}  \tag{1}\]  
where \(q\) is the location of a pixel, \(d\) is the estimated disparity of this pixel, \(\mathbf{I}_{L}\) and \(\mathbf{I}_{R}\) are the left and right images, respectively, \(\
abla_{x}\) and \(\
abla_{y}\) are the gradients of this pixel in the horizontal and vertical directions, respectively, \(T_{Census}\) represents the Census transformation [28], and Ham is the Hamming Distance computation. Left and right images often appear different at the same location due to lighting conditions and image sensing inhomogeneity. These two matching costs are adopted because they can significantly reduce the misleading effects of pixel-level intensity variations. To consider both matching costs, we make a linear combination of \(\mathbf{C}_{TGD}\) and \(\mathbf{C}_{Census}\) to obtain the primary matching cost, \(\mathbf{C}_{0}\):  
\[\mathbf{C}_{0}(q,d)=\alpha\cdot\mathbf{C}_{TGD}(q,d)+(1-\alpha)\cdot\mathbf{C}_{Census}( q,d), \tag{2}\]  
where \(\alpha\) is a weighting constant. It is set to be 0.95 in the following investigations. The primary matching cost can be further aggregated to include information from surrounding pixels. The aggregation of the primary matching cost is the most crucial step that affects the stereo matching performance. A general form of the aggregated matching cost, denoted as \(\overline{\mathbf{C}}(p,d)\), can be written as  
\[\overline{\mathbf{C}}(p,d)=\sum_{q\in\Omega(p)}W_{0}(p,q)\cdot\mathbf{C}_{0}(q,d), \tag{3}\]  
where \(\Omega(p)\) is the supporting region centered at \(p\), and \(W_{0}(p,q)\) is the aggregation weight. For the well-celebrated algorithms based on the weighted guided image filter, such as those proposed in [10; 12; 16], the aggregation weight, denoted as \(W_{GIF}(p,q)\), can be represented in the following form:  
\[W_{0}=W_{GIF}(p,q)=\sum_{k\in\Omega(p)\cap\Omega(q)}\frac{1}{|\Omega(p)|\cdot |\Omega(k)|}\bigg{(}1+\frac{(\mathbf{I}_{L}(p)-\mu(\mathbf{I}_{L}(k)))\cdot(\mathbf{I}_{L }(q)-\mu(\mathbf{I}_{L}(k)))}{\sigma^{2}(\mathbf{I}_{L}(k))+\varepsilon}\bigg{)}, \tag{4}\]  
where \(\mu\) and \(\sigma^{2}\) represent the mean value and variance operations, respectively, and \(\varepsilon\) is a small constant introduced to avoid division by zero. From (4), we know that \(W_{GIF}\) is closely related to the patterns on \(\mathbf{I}_{L}\). Besides, \(W_{GIF}\) depends on the spatial distribution of the image since its value is a function of the interaction between two regions which are centered at \(p\) and \(q\), denoted as \(\Omega(p)\) and \(\Omega(q)\). In [17], the matching cost values are aggregated based on the minimum spanning tree (MST) being derived from the guidance image, where the aggregation weight, denoted as \(W_{MST}\), is calculated as  
\[W_{0}=W_{MST}(p,q)=\prod_{(u,p)\in\ L(p,q)}\exp(-\frac{|\mathbf{I}_{L}(u)-\mathbf{I}_ {L}(v)|}{\beta}), \tag{5}\]where \(L(p,q)\) is a path determined by the MST between a pixel pair located at \(p\) and \(q\), \(u\) and \(v\) are the coordinates of pixels in the path, and \(\beta\) is a shaping parameter.