# Stereo Digital Image Correlation in MATLAB
## 3 Implementation
### Stereo Matching Implementation
#### 3.3.2 FeatureMatch Function  
FeatureMatch, outlined in Table 10, implements SIFT feature matching using codes available from the VLFeat open-source library of computer vision algorithms. More specifically, VLFeat's vl_sift function is used to determine the keypoint locations and descriptors of F and G in lines 3-4. The keypoints of F which fall within the perimeter of at least one subset (square subsets equivalent in size to that specified for the subset under consideration are used) are identified in line 5. Only these keypoints of F are retained, in line 6, in order to reduce the computation time of VLFeat's vl_ubcmatch function in determining matching keypoint pairs between F and G in lines 7-8.  
For each subset, the 20 closest keypoints to its center position are identified in line 9. The for loop of line 13 cycles through the subsets using MSAC to determine reliable affine transformation parameters, which are used by Equation (31) to compute the corresponding second-order SFPs.  
MSAC is implemented using MATLAB's ransac function. Two anonymous functions are used in the call to ransac. RansacModel, defined in line 10, determines the affine transformation parameters from the keypoint locations by solving Equation (29). RansacError, defined in line 11, evaluates Equation (30) to determine each keypoint's squared error distance (for keypoints identified to be relevant to the subset). The fifth argument of ransac sets \(\tau=1\) pixel2 and the final argument specifies the confidence that the maximum number of inliers are determined. The fifth and sixth arguments of ransac, as well as the number of nearest keypoints used for each subset (line 9), can be altered to suit the reader's needs. The try statement of line 14 catches instances where ransac fails to identify three keypoint inliers. As such, the SFP initial estimates of these subsets, stored in P, remain NaN as initialized on line 12.  
\begin{table}
\begin{tabular}{c l} \hline \hline
**Line Numbers** & **Task Performed** \\ \hline Line 2 & **if** VLFeat library is not setup, then return an error; \\ Line 3–4 & Compute keypoint locations and descriptors for F and G using vl_sift; \\ Line 5 & Determine vector KptsInVacinity identifying the keypoints of F which fall within the perimeter of the square subsets, equivalent in size to that specified for the subset under consideration, of P; \\ Line 6 & Eliminate keypoints (and their associated descriptors) of F which do not fall within the perimeter of any of the subsets; \\ Line 7–8 & Determine matching keypoints using vl_ubcmatch; \\ Line 9 & Determine the 20 nearest keypoints for each subset stored in matrix \\  & relevantKpts; \\ Line 10–11 & Define anonymous functions RansacModel and RansacError for \\  & determining affine transformation parameters (of Equation (29)) and \\  & evaluating Equation (30) respectively; \\ Line 12 & Initialise P as NaNs; \\ Line 13 & **for** subset number q = 1 to number of subsets, **do** \\ Line 14 & **try** \\ Line 15 & Use MSAC to determine affine transformation parameters for \\  & subset q from its relevant keypoints; \\ Line 16 & Convert affine transformation parameters to second-order SFPs \\  & using Equation (31); \\ Line 17 & **end try** \\ Line 18 & **end for** \\ Line 19 & Display information for SIFT feature matching; \\ \hline \hline \end{tabular}
\end{table}
Table 10: FeatureMatch algorithm summary.