# Stereo Digital Image Correlation in MATLAB
## 2 Framework Theory
### Subset Matching
#### 2.6.2 Stereo Matching  
Determining reliable out-of-plane displacements in the world CS requires an angle between the optical axes of the cameras of between 15\({}^{\circ}\) and 35\({}^{\circ}\)[5; 68]. As such, stereo matching uses the second-order SF since subsets experience complex deformation between the FIS1 and FIS2 due to this perspective change [41]. Figure 3: Schematic illustration of the displacement transformation process. Note that a projection line represents the combined process of distortion correction and triangulation. Traditionally, template matching, which utilizes image rectification, was used to determine SFP initial estimates for stereo matching [69]. However, image rectification is susceptible to errors in the calibration parameters, can cause aliasing in the rectified images and interpolation during image rectification can lead to errors in the determined SFPs [70]. As such, feature matching methods are becoming favored [41]. ADIC3D's feature matching method is based on that proposed by [PERSON] et al. [71]. It uses the scale-invariant feature transform (SIFT) feature matching algorithm [72] to identify corresponding keypoints between the images (where a keypoint is a unique feature in an image) and the affine transformation mapping model to mathematically relate the coordinates of these keypoint pairs between the images. The SIFT algorithm is used because it is robust in translation, rotation, image scaling, variation in illumination, affine transformation and moderate perspective change. SIFT identifies keypoints that are scale invariant and computes a descriptor, in the form of a 128-dimensional vector, for each keypoint based on the light intensity gradient information in the vicinity of the keypoint. For each keypoint of the FIS1, the Euclidean distance between its descriptor and that of every keypoint of the FIS2 is determined. The two keypoints of the FIS2 with the smallest descriptor distances are identified. If the ratio of the smallest to second smallest descriptor distance is less than 0.8, the keypoint of the FIS2 with the smallest descriptor distance is designated as the matching keypoint of the keypoint of the FIS1 [72]. Otherwise, this keypoint of the FIS1 is discarded. The affine transformation relates a keypoint pair as  
\[\left[ \begin{array}{c}x_{s_{2}}^{k}\\ y_{s_{2}}^{k}\end{array} \right]=\left[ \begin{array}{cc}1+a_{1}&a_{2}&a_{3}\\ a_{4}&1+a_{5}&a_{6}\end{array} \right]\left[ \begin{array}{c}x_{s_{1}}^{k}\\ y_{s_{1}}^{k}\\ 1\end{array} \right]. \tag{29}\]  
Here \(\mathbf{x}_{s_{1}}^{k}=\left[ \begin{array}{cc}x_{s_{1}}^{k}&y_{s_{1}}^{k}\end{array}  \right]^{T}\) and \(\mathbf{x}_{s_{2}}^{k}=\left[ \begin{array}{cc}x_{s_{2}}^{k}&y_{s_{2}}^{k}\end{array}  \right]^{T}\) are the locations of the \(k^{\text{th}}\) keypoint in the FIS1 and FIS2 respectively while \(a_{1}\) through \(a_{6}\) are the affine transformation parameters. Given three or more keypoint pairs, the affine transformation parameters can be solved either as a system of linear equations or through linear least-squares respectively. The \(K\) many \(\mathbf{x}_{s_{1}}^{k}\) that are nearest to the subset's center position are used to determine the affine transformation parameters of the subset. However, since SIFT often returns false keypoint pairs, the m-estimator sample consensus (MSAC) method [73] is used to remove these false keypoint pairs when determining the affine transformation parameters. False keypoint pairs are identified as those which have a squared error distance greater than a predefined threshold, \(\tau\). The squared error distance of the \(k^{\text{th}}\) keypoint pair, \(E_{k}^{dist}\), is calculated as  
\[E_{k}^{dist}=\left(x_{s_{2}}^{k}-(1+a_{1})x_{s_{1}}^{k}-a_{2}y_{s_{1}}^{k}-a_ {3}\right)^{2}+\left(y_{s_{2}}^{k}-a_{4}x_{s_{1}}^{k}-(1+a_{5})y_{s_{1}}^{k}-a _{6}\right)^{2}. \tag{30}\]  
ADIC3D uses \(K=20\), \(\tau=1\) pixel2 and a confidence, specifying the probability that MSAC finds the maximum number of inliers, of 99.5%.