# A Novel 3D Topography Stitching Algorithm Based on Reflectance and Multimap
## 2 Materials and Methods
### New Reflectance-Based Stitching Algorithm
#### 2.2.3 Two-Step Reflectance Algorithm  
The study of the contrast optimization curve of the reflectance map in the optimization process, by plotting the maximum of the autocovariance matrix as a function of the light angle, highlights a pseudo-periodicity of 180\({}^{\circ}\). In fact, this pseudo-periodicity is explained by the fact that a symmetry (or a pseudo-symmetry) is found for a given lighting angle, modulo 180\({}^{\circ}\). The main source of pseudo-symmetry is the topography itself. Topographies with different spatial distribution of features, such as indentations, grooves and defects, produce different reflectance maps where the best lighting angles for maximization of contrast differ. On the other hand, the pseudo-symmetry partially results from the distance of large features of the surface, such as defects, from the lighting source. The shorter this distance, the more structures are in the shadow of these large features, especially for lighting at grazing angle. Moreover, as measured surfaces are never perfectly symmetric (due to measurement errors), contrary to simulated surfaces, their pseudo-symmetry influences the value of maximum contrast for a given lighting angle \(\phi\), and creates a pseudo-periodicity in the contrast optimization curve of the reflectance map. Fortunately, this pseudo-periodicity makes the solution of the optimization process unique, i.e., a unique in-plane lighting angle provides the best contrast. By considering this pseudo-periodicity, a smarter optimization algorithm can be used. The idea is to proceed in two steps. The first is a coarse step, which aims to find a rough estimate of the best lighting \(\phi\) angle inside a range of 0\({}^{\circ}\) to 180\({}^{\circ}\) (half the range of the previous algorithm) by evaluating the solution at every 10\({}^{\circ}\). Then, a more precise step evaluates solutions in the neighborhood of the coarse solution and at 180\({}^{\circ}\) of this coarse solution. The solution can be evaluated every 1\({}^{\circ}\) for more precision. Potentially, this process can be repeated for even more precision, such as every 0.1\({}^{\circ}\) or 0.01\({}^{\circ}\), depending on the precision required by the user for a reasonable algorithm run time. Figure 5 presents the optimized reflectance map obtained after the two-step optimization algorithm (Figure 5a), along with the optimization curve for the determination of the best in-plane lighting angle (Figure 5b). Once again, an in-plane lighting angle of 274\({}^{\circ}\) provides the best contrast, which results in the same exact reflectance map as the exhaustive enumeration optimization. Figure 5: Optimized reflectance map of an indented surface (**a**) and optimization curve (**b**), where each square is a tested lighting angle \(\phi\) solution, obtained with the two-step reflectance optimization (\(\theta_{light}=90^{\circ}\)). This strategy evaluates a lot fewer solutions compared to the exhaustive enumeration method, which results in a faster algorithm for an equivalent or greater precision. A speed comparison between the exhaustive enumeration optimization and the two-step optimization is provided in Table 3. Using the two-step optimization algorithm results in a significant gain of speed, roughly equal to six. A flowchart summing up the three variants of the rising sun 3D topography stitching algorithm based on reflectance and multimap is provided in Figure 6.  
Figure 6: Flowchart of the three variants of the rising sun 3D topography stitching algorithm: the naive reflectance (NR), the exhaustive enumeration reflectance (EER) and the two-step reflectance (TSR). \begin{table}
\begin{tabular}{c c c} \hline \hline
**Elementary Topography** & **Indentation** & **Abrasion** \\ \hline X \(\times\) Y Dimensions (pixels) & 2040 \(\times\) 2040 & 480 \(\times\) 640 \\ \hline Exhaustive Enumeration Run Time (s) & 97.3 & 6.52 \\ \hline Two-Step Run Time (s) & 16.3 & 0.89 \\ \hline Speed Up Ratio & 5.96 & 7.33 \\ \hline \hline \end{tabular}
\end{table}