# Simplified High-Performance Cost Aggregation for Stereo Matching
## 2 Methods
### The Proposed Aggregation Method
#### 2.2.1 The First Step: Horizontal Aggregation  
In the first step, the proposed aggregation cost assumes the least squared difference from the primary matching cost. In addition, the cost has fewer differences with the horizontal 2 neighbors of each  
where  
\[\begin{array}{l}H_{x}=\sum\limits_{y=1}^{N}\left[\overline{C}_{1}(x,y,d)-C_{0}( x,y,d)\right]^{2}\\ \hskip 14.226378 pt+2\lambda\cdot\sum\limits_{y=2}^{N-1}\Big{\{}\left[\overline{C}_ {1}(x,y,d)-\overline{C}_{1}(x,y-1,d)\right]^{2}+\left[\overline{C}_{1}(x,y,d)- \overline{C}_{1}(x,y+1,d)\right]^{2}\Big{\}}.\end{array} \tag{9}\]  
In minimizing each of the objective function \(H_{x}\), we may take partial derivative of it with respect to \(\overline{C}^{\prime}(x,y,d)\):  
\[\frac{\partial H_{x}}{\partial\overline{C}_{1}(x,y,d)}=0,\ \ y\in\{1,2,\ldots,N\} \tag{10}\]  
This results in the following \(N\) equations for different \(y\):  
\[\left\{\begin{array}{l}(1+2\lambda)\cdot\overline{C}_{1}(x,1,d)-2\lambda \cdot\overline{C}_{1}(x,2,d)=C_{0}(x,1,d)\\ -2\lambda\cdot\overline{C}_{1}(x,y-1,d)+(1+4\lambda)\cdot\overline{C}_{1}(x, y,d)-2\lambda\cdot\overline{C}_{1}(x,y+1,d)=C_{0}(x,y,d),\ \ y\in\{2,3,\ldots,N-1\}\\ -2\lambda\cdot\overline{C}_{1}(x,N-1,d)+(1+2\lambda)\cdot\overline{C}_{1}(x, N,d)=C_{0}(x,N,d).\end{array}\right. \tag{11}\]  
If we define  
\[\mathbf{A}_{h}=\begin{bmatrix}1+2\lambda&-2\lambda&&&0\\ -2\lambda&1+4\lambda&-2\lambda&&&\\ &-2\lambda&\ddots&\ddots&&\\ &&\ddots&1+4\lambda&-2\lambda\\ 0&&&-2\lambda&1+2\lambda\end{bmatrix},\ B(x)=\begin{bmatrix}\overline{C}_{1}(x,1,d)\\ \vdots\\ \overline{C}_{1}(x,N,d)\end{bmatrix},\ D(x)=\begin{bmatrix}\mathcal{C}_{0}(x,1,d)\\ \vdots\\ \mathcal{C}_{0}(x,N,d)\end{bmatrix}, \tag{12}\]  
Equation (11) can be written in a matrix form as  
\[\mathbf{A}_{h}\cdot B(x)=D(x) \tag{13}\]  
Figure 1: A pixel located at \(p\) and its two horizontal neighbors, denoted as \(\mathbf{N}_{h}(x,y)\).  
Besides, with (12) we observe that:  
\[\overline{\mathbf{C}}_{1}=\left[\begin{array}{ccccc}\overline{\mathbf{C}}_{1}(1,1,d)& \overline{\mathbf{C}}_{1}(1,2,d)&\cdots&\overline{\mathbf{C}}_{1}(1,N,d)\\ \overline{\mathbf{C}}_{1}(2,1,d)&\overline{\mathbf{C}}_{1}(2,2,d)&\cdots&\overline{ \mathbf{C}}_{1}(2,N,d)\\ \vdots&\vdots&\vdots&\vdots\\ \overline{\mathbf{C}}_{1}(M,1,d)&\overline{\mathbf{C}}_{1}(M,2,d)&\cdots&\overline{ \mathbf{C}}_{1}(M,N,d)\end{array}\right]=\left[\begin{array}{c}B(1)^{T}\\ B(2)^{T}\\ \vdots\\ B(M)^{T}\end{array}\right],\]  
\[\mathbf{C}_{0}=\left[\begin{array}{ccccc}\mathbf{C}_{0}(1,1,d)&\mathbf{C}_{0}(1,2,d)& \cdots&\mathbf{C}_{0}(1,N,d)\\ \mathbf{C}_{0}(2,1,d)&\mathbf{C}_{0}(2,2,d)&\cdots&\mathbf{C}_{0}(2,N,d)\\ \vdots&\vdots&\vdots&\vdots\\ \mathbf{C}_{0}(M,1,d)&\mathbf{C}_{0}(M,2,d)&\cdots&\mathbf{C}_{0}(M,N,d)\end{array}\right]= \left[\begin{array}{c}D(1)^{T}\\ D(2)^{T}\\ \vdots\\ D(M)^{T}\end{array}\right], \tag{14}\]  
Taking the whole image into consideration, (13) becomes  
\[\overline{\mathbf{C}}_{1}\cdot\mathbf{A}_{h}^{T}=\mathbf{C}_{0} \tag{15}\]  
The matrix \(\mathbf{A}_{h}\) is tridiagonal, symmetric, and sparse. This N-by-N matrix is invertible for positive \(\lambda\)[29]. From (15), we may obtain the proposed aggregated matching cost, \(\overline{\mathbf{C}}_{1}\), by inverting \(\mathbf{A}_{h}\):  
\[\overline{\mathbf{C}}_{1}^{T}=\mathbf{A}_{h}^{-1}\cdot\mathbf{C}_{0}^{T} \tag{16}\]  
This procedure has the advantage that the matching cost can be calculated using a simple linear combination with constant weights while the resultant matching cost has a small difference with the horizontal neighborhoods, and only a smooth transition in this direction is possible.