# Simplified High-Performance Cost Aggregation for Stereo Matching
## 2 Methods
### The Proposed Aggregation Method
#### 2.2.2 The Second Step: Vertical Aggregation  
Similar to the first step, we can create an objective function, denoted as \(J_{v}\), for an aggregated matching cost, \(\overline{\mathbf{C}}_{2}\). The function applies constraints in the vertical direction while enforces its least squared difference from the matching cost aggregated in the first step, \(\overline{\mathbf{C}}_{1}\):  
\[ \begin{array}{l}J_{v}=\sum\limits_{y=1}^{N}\left\{\sum\limits_{x=1}^{M} \left[\overline{\mathbf{C}}_{2}(x,y,d)-\overline{\mathbf{C}}_{1}(x,y,d)\right]^{2} \right.\\ \left.+2\lambda\cdot\sum\limits_{x=2}^{M-1}\left\{\left[\overline{\mathbf{C}}_{2} (x,y,d)-\overline{\mathbf{C}}_{2}(x-1,y,d)\right]^{2}+\left[\overline{\mathbf{C}}_{2} (x,y,d)-\overline{\mathbf{C}}_{2}(x+1,y,d)\right]^{2}\right\}\right\}\\ \equiv\sum\limits_{y=1}^{N}V_{y}.\end{array}  \tag{17}\]  
We assume the objective function is composed of sub-functions \(V_{y}\), which are mutually independent in the horizontal direction. \(\overline{\mathbf{C}}_{2}\) can be solved by taking a partial derivative of \(V_{y}\) with respect to \(\overline{\mathbf{C}}_{2}\) in each column. By accumulating the results through the whole image, we have  
\[\overline{\mathbf{C}}_{2}=\mathbf{A}_{v}^{-1}\cdot\overline{\mathbf{C}}_{1} \tag{18}\]  
where  
\[\mathbf{A}_{v}= \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}  \tag{19}\]Again, the matrix \(\mathbf{A}_{v}\) is an M-by-M invertible tridiagonal sparse matrix for positive \(\lambda\)[29]. Combining (18) and (16), and considering that \(\mathbf{A}_{h}\) is symmetric, we have  
\[\overline{\mathbf{C}}_{2}=\mathbf{A}_{v}^{-1}\cdot\overline{\mathbf{C}}_{1}=\mathbf{A }_{v}^{-1}\cdot\mathbf{C}_{0}\cdot\left(\mathbf{A}_{h}^{-1}\right)^{T}=\mathbf{A}_ {v}^{-1}\cdot\mathbf{C}_{0}\cdot\mathbf{A}_{h}^{-1}. \tag{20}\]  
From (20), we know that the aggregation of the primary matching cost can be simplified as a series of matrix multiplication. The horizontal aggregation weight, \(\mathbf{A}_{h}\), and the vertical aggregation weight, \(\mathbf{A}_{v}\), are constant tridiagonal matrices of the parameter \(\lambda\). Their inverses can be calculated beforehand once the image sizes, \(M\) and \(N\), are known. Under this condition, the computational complexity of the proposed algorithm is much simpler than most aggregation approaches. Taking \(M=480\), \(N=720\), and \(\lambda=7\) as an example, Figures 2 and 3 show visualized representations of \(\mathbf{A}_{v}^{-1}\) in two and three dimensions. It can  
As \(\mathbf{A}_{v}^{-1}\) is symmetric and sparse, its element values in the row and column directions follow the same pattern. For a fixed image size, \(\mathbf{A}_{v}^{-1}\) is completely defined by the only parameter \(\lambda\). Figure 4 demonstrates the element values of \(\mathbf{A}_{v}^{-1}\) as a function of \(\lambda\). The image size is also 480-by-720, and only elements on row 240 are depicted. Also, as observed in Figure 4, the distribution of the sparse matrix becomes smoother when \(\lambda\) is larger, which implies a larger effective range of the aggregation. When \(\lambda\) is smaller, the distribution of the sparse matrix is sharper, and the effective range of the matching cost aggregation is smaller. This observation is consistent with (7) and (17) that, when the value of \(\lambda\) is larger, the objective functions, \(J_{h}\) and \(J_{v}\), have stronger constraints on the aggregated matching costs, \(\widetilde{\mathcal{C}}_{1}\) and \(\widetilde{\mathcal{C}}_{2}\). From the above analysis, we have gathered that the effective range of \(\mathbf{A}_{h}^{-1}\) and \(\mathbf{A}_{v}^{-1}\) is similar to the size of the aggregation window or the length of an aggregation path in the local and non-local algorithms. For images with larger resolutions, a larger value of \(\lambda\) is required to effectively aggregate the matching cost in a broader range.