# Stereo Digital Image Correlation in MATLAB
## 3 Implementation
### Correlation Implementation  
Both stereo and temporal matching make use of correlation, detailed in Section 2.3, which is implemented using the three subroutines: SubShapeExtract, SFExpressions, and SubCorr. These subroutines are discussed briefly since they are identical to those used in ADIC2D [53]. SubShapeExtract, detailed in Table 6, determines \(f_{i}\), \(\
abla f_{i}\) and \(\Delta x_{i}\) of a subset based on inputs SubSize, SubShape, Xos, \(F\), \(\
abla F\), and SubExtract. Note that variables with subscript \(i\) refer to the full set of this variable for the subset (i.e., \(f_{i}\) refers to \(f_{i}\forall i\in I\)) throughout Section 3.2. \(\
abla F\) is the light intensity gradient of the reference image whereas SubExtract is an anonymous function which extracts a square subset from a matrix based on the size and position of the subset. For SubShape defined as 'Circle', SubSize specifies the diameter. \begin{table}
\begin{tabular}{c l} \hline \hline
**Line Numbers** & **Task Performed** \\ \hline Lines 2–3 & Compute image names of both image series; \\ Lines 4–5 & Compute number of images and size of the first image in first image series; \\ Lines 6–7 & Create regularly spaced reference subset positions, Xos; \\ Line 8 & Remove subsets containing invalid pixels which are defined by Mask; \\ Line 9–12 & Pre-assign ResultData structure array; \\ Line 13 & Call subroutine StereoMatch to perform stereo matching; \\ Line 15 & Call subroutine ImgCorr to perform temporal matching of first image series; \\ Line 17 & Call subroutine ImgCorr to perform temporal matching of second image series; \\ Line 18 & Call subroutine CSTrans to perform displacement transformation from the distorted sensor CSs to the world CS; \\ \hline \hline \end{tabular}
\end{table} 
Table 5: ADIC3D algorithm summary. \begin{table}
\begin{tabular}{c c} \hline \hline
**Line Numbers** & **Task Performed** \\ \hline Line 2 & **switch SubShape;** \\ Line 3 & **case SubShape = ’Square’, do** \\ Line 4–6 & Extract \(f_{i}\) and \(\
abla\!f_{i}\) using SubExtract; \\ Line 7 & Compute \(\Delta x_{i}\) using SubSize; \\ Line 8 & **case SubShape = ’Circle’, do** \\ Line 9–11 & Extract \(f_{i}\) and \(\
abla\!f_{i}\) using SubExtract; \\ Line 12 & Compute \(\Delta x_{i}\) using SubSize; \\ Line 13 & Determine mask of elements that fall within the circular subset; \\ Line 14–16 & Use mask to extract appropriate data for circular subset; \\ Line 17 & **end switch** \\ \hline \hline \end{tabular}  
SFExpressions returns anonymous functions for expressions that are dependent on the SF order, as outlined in Table 7. These anonymous functions are as follows: W defines Equation (9); dFdWdP defines \(\
abla\!f_{i}\frac{\partial\mathbf{W}_{i}}{\partial\mathbf{P}}\); SFPVec2 Mat defines Equation (22); Mat2 SFPVec extracts the SFPs from SFPVec2 Mat; and StopCrit defines Equation (23). ADIC3D allows for the zero, first, or second-order SFs to be used by setting SFOrder to 0, 1, or 2 respectively.  
\end{table} 
Table 7: SFExpressions algorithm summary. \begin{table}
\begin{tabular}{c c} \hline \hline
**Line Numbers** & **Task Performed** \\ \hline Line 2 & **switch SFOrder** \\ Line 3–8 & **case SFOrder = 0, do** **assign functions for zero-order SF; \\ Line 9–14 & **case SFOrder = 1, do** **assign functions for first-order SF; \\ Line 15–20 & **case SFOrder = 2, do** **assign functions for second-order SF; \\ Line 21 & **end switch** \\ \hline \hline \end{tabular}  
SubCorr performs the core operations of correlation for a subset as outlined in Table 8. Its inputs are the interpolation coefficients of the deformed image, \(f_{i}\), \(\
abla\!f_{i}\), SubSize, SFOrder, Xos, \(\Delta x_{i}\), initial estimates for P and StopCritVal. SubCorr returns P, C, Iter, and StopVal. The size of vector P is consistent with that of the second-order SF. Thus, the elements of \(\mathbf{P}^{SF2}\), not relevant to the specified SF order, remain zero.  
\end{table} 
Table 8: SubCorr algorithm summary.