# Matchability and Uncertainty-Aware Iterative Disparity Refinement for Stereo Matching
## 3 Methods
### The Matchability and Uncertainty Decoder
#### 3.1.2 Prediction of Disparity Uncertainty  
The disparity estimation in ill-posed regions relies heavily on geometric priors rather than feature matching, limiting the accuracy. The more stable and practical way for downstream tasks is to filter out less reliable predictions. However, uncertainty or confidence estimation that rely on cost volume [19, 43] is not directly applicable to RAFT-based methods. Therefore, we follow [17, 39] in capturing aleatoric uncertainty to indicate disparity error. Unlike methods that use a dedicated uncertainty subnetwork, our method integrates the uncertainty decoder into the iterative disparity refinement framework for joint training. In stereo matching, the disparity error is assumed to be Laplacian-distributed [41]. The probability density and the joint-training negative maximum likelihood loss function are as follows:  
\[ \begin{split}\text{p}(\hat{d}|I_{t},I_{t};\theta)=\frac{1}{2 \beta}e^{-\frac{\left\lVert\hat{d}-d_{\text{gt}}\right\rVert_{1}}{\beta}}\\ \mathcal{L}_{1}^{\text{d,u}}=-\log\text{p}(\hat{d}|I_{t},I_{t}; \theta)=\log 2+\log\beta+\frac{\left\lVert\hat{d}-d_{\text{gt}}\right\rVert _{1}}{\beta},\end{split}  \tag{4}\]  
where \(d_{\text{gt}}\) is disparity ground truth, \(\beta\) is the scale parameter of Laplacian distribution, \(\theta\) denotes the model parameters, and \(\left\lVert\cdot\right\rVert_{1}\) denotes the L1 norm. To ensure numerical stability during training [17], the uncertainty is defined as \(\hat{u}=\log\beta^{2}\), and the constant term is omitted:  
\[\mathcal{L}_{1}^{\text{d,u}}=\frac{\hat{u}}{2}+e^{-\frac{\hat{u}}{2}}\left\lVert \hat{d}-d_{\text{gt}}\right\rVert_{1}. \tag{5}\]  
Equation (5) can be simply applied to the loss in the baseline [12]:  
\[\mathcal{L}_{2}^{\text{d,u}}=\sum_{t=1}^{T}\gamma^{T-t}(\frac{\hat{u}_{t}}{2} +e^{-\frac{\hat{u}_{t}}{2}}\left\lVert\hat{d}_{t}-d_{\text{gt}}\right\rVert_{ 1}), \tag{6}\]  
where \(\gamma\) is a weighting parameter (usually set to 0.9). Preliminary experiments are performed by adding the uncertainty prediction network to the baseline as the loss function replaced by Equation (6). The endpoint error (EPE) curves in Figure 4 show the decrease in disparity accuracy due to the simple design of the joint training. To avoid an unnecessary decrease in disparity accuracy, the uncertainty is constrained as \(\hat{u}_{t}\in[u_{\text{min}},u_{\text{max}}]\), resulting in a modified joint-training loss function:  
\[ \begin{split}&\mathcal{L}^{\text{u}}=\frac{\hat{u}}{2}+e^{- \frac{\hat{u}}{2}}\text{min}(\text{max}(\left\lVert\hat{d}_{t}-d_{\text{gt}} \right\rVert_{1},\epsilon_{\text{min}}),\epsilon_{\text{max}}))\\ &\mathcal{L}^{\text{d,u}}=\sum\limits_{t=1}^{T}\gamma^{T-t}( \left\lVert\hat{d}_{t}-d_{\text{gt}}\right\rVert_{1}+\mathcal{L}^{\text{u}} )\end{split} , \tag{7}\]  
where \([\epsilon_{\text{min}},\epsilon_{\text{max}}]\) denotes the range of disparity errors perceived by the model, corresponding to the effective uncertainty range \([u_{\text{min}}=\log\epsilon_{\text{min}}^{2},u_{\text{max}}=\log\epsilon_{ \text{max}}^{2}]\). The range constraint is used to avoid model degradation caused by errors that are too small or too large [17]. The constrained uncertainty is computed as:  
\[ \begin{split}\hat{v}_{t}&=f_{\theta^{\text{u}}}^{\text {u}}(H_{t},C^{\text{mtc}}(\hat{D}_{t}),\hat{d}_{t})\\ \hat{u}_{t}&=\log(\epsilon_{\text{min}}^{2}+( \epsilon_{\text{max}}^{2}-\epsilon_{\text{min}}^{2})\sigma(\hat{v}_{t}))\end{split} \, \tag{8}\]  
where \(f_{\theta^{\text{u}}}^{\text{u}}\) denotes a simple convolutional network with parameter \(\theta^{\text{u}}\). In addition, to keep the pixel-wise correspondence between disparity and uncertainty after upsampling, the \(\hat{d}_{t}^{\text{up}}\) and \(\hat{u}_{t}^{\text{up}}\) are computed together via the joint disparity-uncertainty upsampler. It is shown in Figure 4 that the proposed method greatly alleviates the decrease in disparity accuracy introduced by the joint training.