# Mapping with Pleiades--End-to-End Workflow
## 4 Methods
### Digital Surface Model Generation
#### 4.2.2 Image Matching
For each direction \(\mathbf{r}\) an aggregated matching cost \(L_{\mathbf{r}}(\mathbf{p},d)\) is recursively calculated as  
\[L_{\mathbf{r}}(\mathbf{p},d)=C_{\mathbf{p}}(d)+\min_{d^{\prime}\in\mathcal{D}}\left(L_{ \mathbf{r}}(\mathbf{p}-\mathbf{r},d^{\prime})+V(d,d^{\prime})\right). \tag{4}\]  
Figure 9: Image matching principle with epipolar rectified input images. The main steps are calculation of the disparity space image, cost aggregation and disparity selection. The final disparity map \(D\) holds the shifts in column directions for each pixel such that they point from the reference image \(X_{r}\) to the search image \(X_{s}\). Then, the 8 aggregated costs are summed at each pixel, yielding the aggregated cost volume  
\[S(\mathbf{p},d)=\sum_{\mathbf{r}}L_{\mathbf{r}}(\mathbf{p},d)\,, \tag{5}\]  
where the minimum at each pixel is chosen as the final disparity  
\[d_{\mathbf{p}}=\operatorname*{arg\,min}_{d}S(\mathbf{p},d)\,. \tag{6}\]  
Since 3D breaklines are often visible in the input images as local changes of the grayvalues, the penalty \(P_{2}\) can be adjusted w.r.t. these local changes of the reference input image \(I\) in the current direction \(\mathbf{r}\)[61]. As in the original paper no details on the adaptive penalty function are given, we propose to define \(P_{2}\) as a function of \(I\), \(\mathbf{r}\) and three parameters \(\epsilon\), \(\tau\) and \(P_{2}^{{}^{\prime}}\) as  
\[P_{2}(I,\epsilon,\tau)=\max\left(\frac{\mu_{I}\cdot P_{2}^{{}^{\prime}}}{|I_{ \mathbf{p}}-I_{\mathbf{q}}|+\epsilon},P_{1}+\tau\right) \tag{7}\]  
with \(\mu_{I}\) the mean gradient in column and line direction of \(I\), \(\mathbf{q}\) the adjacent pixel coordinate of \(\mathbf{p}\) based on \(\mathbf{r}\), \(P_{2}^{{}^{\prime}}\) the initial penalty value and some \(\epsilon\) to avoid a division by zero if \(I_{\mathbf{p}}\) equals \(I_{\mathbf{q}}\). The parameter \(\epsilon\) is set to \(\epsilon=\left\{\min(|I_{\mathbf{p}}-I_{\mathbf{q}}|)\mid\forall|I_{\mathbf{p}}-I_{\mathbf{q}} |\
eq 0\right\}\), that is, \(\epsilon\) becomes 1 for most images of type uint8 or uint16. The equation also ensures that \(P_{2}\) is always larger than \(P_{1}\) by at least a predefined \(\tau\). We set \(\tau\) in a pragmatic way to \(\tau=P_{1}+(P_{2}^{{}^{\prime}}-P_{1})/100\) such that it automatically adapts to the input penalty values. This extension results in twofold improvements: (1) in homogeneous regions the penalty \(P_{2}\) becomes huge such that large (mostly incorrect) disparity jumps are omitted and (2) at pixel locations with large local grayvalues changes \(P_{2}\) become smaller and thus 3D jumps are cheaper for the optimization. Since 3D breaklines often correspond to grayvalue changes such jumps are better modeled by the algorithm. The resulting disparities \(d_{\mathbf{p}}\) are calculated at integer precision. To get subpixel refinements the classical approach is to fit a polynomial of order 2, that is, a parabola, into the three values surrounding the best-estimated disparity. The minimum of this polynomial, which can be extracted analytically, then defines the subpixel disparity. For outlier detection and interpolation, the following options are implemented. A classical left-right consistency check is performed by employing backmatching. Disparities with a backmatching distance larger than a given threshold are marked as outliers. The standard threshold value is just above \(\sqrt{2}\) such that a matching is correct if the backmatching hits within the local \(3\times 3\) window (e.g., \(1.5\) pixel). Then also a threshold on the aggregated cost is performed. Lastly, a peak filter detects connected regions (cf. Reference [61]), where small islands are discarded. In the next step, discarded pixels are classified as blunder or as occlusions as described in Reference [61]. Then, blunder locations are linearly interpolated based on their neighbors, while occluded locations are interpolated toward the ground level to avoid blurring at 3D breaklines.