# Hierarchical Guided-Image-Filtering for Efficient Stereo Matching
## 2 Proposed Method  
### The Cost Aggregation Based on the Pervasive Guided-Image-Filtering (PGIF)  
This section presents the basic procedure of the pervasive guided-image-filtering (PGIF) [25] scheme. It serves as the definitions of some of the variables and algorithms for the proposed scheme to be shown in the next section. In the GIF-based stereo matching algorithms, such as WGIF [21], GDGF [22], and PGIF [25] are discussed in the last section. The aggregated cost, \(\overline{C}_{d,0}(p)\) is a linear function of the guidance image, \(I_{G}\) at a local disparity patch such that:  
\[\overline{C}_{d,0}(p)=a_{d,0}(p)\cdot I_{G}(p)+b_{d,0}(p), \tag{1}\]  
where \(p=(x,y)\) is the location of the central pixel and \(d\) indicates the disparity. Note that \(\overline{C}_{d,0}(p)\) have three dimensions \((x,y,d)\) and is often denoted as the aggregated cost volume. Likewise, \(a_{d,0}(p)\) and \(b_{d,0}(p)\) can also be called the parameter volumes of the model. The second subscript, \(0\), indicates that these values are related to the original resolution. For the following stereo matching operations, we regard the left image as the reference image, such that \(I_{G}=I_{L,0}\), and the right image as the target image. The disparity map, \(D(p)\) is composed of the disparity value corresponding to the minimum aggregated cost at each location \(p\):  
\[D(p)=\operatorname*{argmin}_{d}\overline{C}_{d,0}(p). \tag{2}\]In order to solve for \(a_{d,0}(p)\) and \(b_{d,0}(p)\), we proposed an objective function in Reference [25], which includes a weighted sum of the squared difference between the linear model and a primary matching cost, denoted as \(C_{d,0}(q)\), and a regularization term:  
\[E_{d,0}(p)=\sum_{q\in\Omega_{0}(p)}\omega_{0}(p,q)\cdot\{\big{[}a_{d,0}(p)\cdot I _{L,0}(q)+b_{d,0}(p)-C_{d,0}(q)\big{]}^{2}+\varepsilon(p)\cdot[a_{d,0}(p)]^{2}\} \tag{3}\]  
where \(\Omega_{0}\) is the support window for a pixel located at \(p\), \(\omega_{0}(p,q)\) is the weight that reflects the contribution of a pixel located at \(q\), and \(\varepsilon(p)\) is the regularization factor to limit the magnitude of \(a_{d,0}(p)\). Because of an efficient iterative computation scheme, to be presented below, the support window is the whole image. The primary matching cost, \(C_{d,0}(q)\), represents the degree of match between a pixel located at \(q\) of the left image and a pixel located at \(q+d\) of the right image. This cost is smaller for a higher degree of match. We employ a truncated version of the absolute gradient difference to define the cost:  
\[C_{d,0}(q)=\min\big{(}\big{|}\
abla_{x}I_{L,0}(q)-\
abla_{x}I_{R,0}(q+d)\big{|},\tau\big{)}+\min\big{(}\big{|}\
abla_{y}I_{L,0}(q)-\
abla_{y}I_{R,0}(q+d) \big{|},\tau\big{)} \tag{4}\]  
where \(I_{L,0}\) and \(I_{R,0}\) are the left and right images of the stereo pair in the original resolution, \(\
abla_{x}\) and \(\
abla_{y}\) are the horizontal and vertical gradients, respectively, and \(\tau\) is the truncation threshold, normally assigned as 2. The use of the threshold helps to reduce the mismatch in obscured or noisy regions. The optimum values of the parameters in Equation (3), represented as \(a^{*}_{d,0}(p)\) and \(b^{*}_{d,0}(p)\), are obtained by minimizing the objective function Equation (3):  
\[ \begin{array}{l}\frac{\partial\varepsilon_{d,0}(p)}{\partial a_{d,0}(p)}=0 \\ \frac{\partial\varepsilon_{d,0}(p)}{\partial b_{d,0}(p)}=0\end{array}