# A 117 Line 2D Digital Image Correlation Code Written in MATLAB

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Framework Theory

#### 2.1. Calibration

#### 2.1.1. Homogeneous Coordinates

#### 2.1.2. Pinhole Camera Model

#### 2.1.3. Radial Distortion Model

#### 2.1.4. Calibration Process

#### 2.2. Correlation

#### 2.2.1. Correlation Criterion

#### 2.2.2. Shape Function

#### 2.2.3. Interpolation

^{0}and C

^{1}continuous for linear and cubic polynomial interpolation, respectively. Refer to the work of Keys [46] for more information on cubic polynomial interpolation.

^{2}continuous. Refer to the work of Hou et al. [47] for an in-depth discussion of bi-cubic b-spline interpolation.

#### 2.2.4. Gaussian Filtering

#### 2.2.5. Optimisation Method

${A}_{1}=2{u}_{x}+{u}_{x}^{2}+u{u}_{xx}$, | ${A}_{2}=2u{u}_{xy}+2(1+{u}_{x}){u}_{y}$, |

${A}_{3}={u}_{y}^{2}+u{u}_{yy}$, | ${A}_{4}=2u(1+{u}_{x})$, |

${A}_{5}=2u{u}_{y}$, | ${A}_{6}={u}^{2}$, |

${A}_{7}=\frac{1}{2}(v{u}_{xx}+2(1+{u}_{x}){v}_{x}+u{v}_{xx})$, | ${A}_{8}={u}_{y}{v}_{x}+{u}_{x}{v}_{y}+v{u}_{xy}+u{v}_{xy}+{v}_{y}+{u}_{x}$, |

${A}_{9}=\frac{1}{2}(v{u}_{yy}+2(1+{v}_{y}){u}_{y}+u{v}_{yy})$, | ${A}_{10}=v+v{u}_{x}+u{v}_{x}$, |

${A}_{11}=u+v{u}_{y}+u{v}_{y}$, | ${A}_{12}=uv$, |

${A}_{13}={v}_{x}^{2}+v{v}_{xx}$, | ${A}_{14}=2v{v}_{xy}+2{v}_{x}(1+{v}_{y})$, |

${A}_{15}=2{v}_{y}+{v}_{y}^{2}+v{v}_{yy}$, | ${A}_{16}=2v{v}_{x}$, |

${A}_{17}=2v(1+{v}_{y})$ | and ${A}_{18}={v}^{2}$. |

#### 2.2.6. Stopping Criterion

#### 2.3. Displacement Transformation

#### 2.4. Strain Computation

## 3. Framework Implementation

`ProcData = ADIC2D(FileNames, Mask, GaussFilt, StepSize, SubSize, SubShape, SFOrder, RefStrat, StopCritVal, WorldCTs, ImgCTs, rho)`” requiring input variables as defined in Table 1 and providing an output variable as a structured array containing data for each analysed image d and subset q as detailed in Table 2.

#### 3.1. `ADIC2D` Function

`ADIC2D`is the main function and is outlined in Table 3. Its purpose is to set up the DIC problem and call the appropriate subroutines.

`ADIC2D`defines variables on a per image and subset basis to allow for complete flexibility in assigning

`Xos`,

`SubSize`,

`SubShape`and

`SFOrder`, i.e., on a per subset basis. Although

`ADIC2D`is capable of this, it assigns the same

`SubSize`,

`SubShape`and

`SFOrder`to each subset (in line 8 based on the inputs) since this is the most common use case. Output variables are pre-assigned in line 8 to allow for the collection of input data used and efficient storage of computed variables. Note that the SFPs are stored in a vector

`P`which corresponds to the size of the second-order SFP vector in Equation (15). Thus, the second-order SFPs of

`P`, not used by the specified SF order, remain zero.

`ADIC2D`calls the subroutine

`ImgCorr`to perform the image correlation as presented above.

`ImgCorr`’s input variables are

`n`(the total number of images in the set), the pre-assigned variables in

`ProcData`,

`FileNames`,

`RefStrat`and

`StopCritVal`. The output variables are

`P`,

`C`,

`Iter`and

`StopVal`which are stored in

`ProcData`. The computed SFPs are then passed to

`CSTrans`to transform displacements to the world CS.

`CSTrans`’s input variables are

`n`,

`ProcData`,

`WorldCTs`,

`ImgCTs`and

`rho`. The output variables are

`Xow`,

`Uw`and MATLAB’s

`CamParams`(containing the intrinsic, extrinsic, and radial distortion parameters) which are stored in

`ProcData`. Note that within the subroutines

`ProcData`is shortened to

`PD`.

`Xos`defined using

`StepSize`and

`SubSize`. Subsets which contain pixels that

`Mask`indicates should not be analysed are removed.

#### 3.2. Correlation Implementation

`ImgCorr`, which performs the correlation on an image bases, i.e., between $F$ and $G$; (ii)

`SubCorr`, which performs the correlation on a subset basis; (iii)

`SFExpressions`, which defines anonymous functions based on the SF order; (iv)

`SubShapeExtract`, which determines input data for

`SubCorr`based on the subset shape, size and position; and (v)

`PCM`, which determines initial estimates for the displacement SFPs.

`SubCorr`’s input variables are the interpolation coefficients, ${\mathit{f}}_{i}$, $\nabla {\mathit{f}}_{i}$,

`SubSize`,

`SFOrder`,

`Xos`, $\Delta {\mathit{x}}_{i}$, initial estimates for $\mathit{P}$ and

`StopCritVal`. Note that throughout Section 3.2 variables with subscript $i$ refer to the full set of this variable for a subset (i.e., $\nabla {\mathit{f}}_{i}$ refers to $\nabla {\mathit{f}}_{i}\forall i\in I$).

`SubCorr`’s output variables are

`P`,

`C`,

`Iter`and

`StopVal`.

`SFExpressions`’s input variable is

`SFOrder`with outputs as anonymous functions to compute $\mathit{W}$, $\nabla {\mathit{f}}_{i}\frac{\partial {\mathit{W}}_{i}}{\partial \mathit{P}}$ and $\Vert \mathit{P}\Vert $. Moreover, two functions are included to compute $\mathit{\omega}$ (given in Equation (22)) and to extract the SFPs from $\mathit{\omega}$.

`SubSize`defines the diameter of the subset.

`SubShapeExtract`is used to determine ${\mathit{f}}_{i}$, $\nabla {\mathit{f}}_{i}$ and $\Delta {\mathit{x}}_{i}$ for a subset based on the inputs

`SubSize`,

`SubShape`,

`Xos`, $F$, $\nabla F$ and

`SubExtract`. $\nabla F$ is the light intensity gradient of the entire reference image and

`SubExtract`is an anonymous function, defined in line 2 of

`ImgCorr`, which extracts a square subset from a matrix based on the position and size of the subset.

`PCM`returns $u$ and $v$ based on inputs $F$, $G$,

`SubSize`,

`Xos`(passed as two vectors as required by

`arrayfun`) and

`SubExtract`.

`FileNames(1)`), whereas the incremental strategy defines the previous image as $F$ (

`FileNames(d-1)`). The incremental strategy handles large deformations between images more reliably; however, if total displacements are required, it suffers from accumulative errors. The variable

`RefStrat`is set to 0 or 1 for the absolute or incremental strategy respectively. Alternate reference strategies may be set by modifying line 8 in

`ImgCorr`.

`SFOrder`to 0, 1 or 2 for the zero, first and second-order SFs, respectively.

#### 3.2.1. `ImgCorr` Function

`ImgCorr`uses two nested for-loops as summarised in Table 4. The outer loop cycles through the image set, whereas the inner loop cycles through the subsets.

`ImgCorr`reads the appropriate image pairs $F$ and $G$ from the image set, depending on the chosen reference strategy, and filters both using MATLAB’s

`imgaussfilt`function. Alternate image filters can be employed by modifying line 5 and 9. Bi-cubic b-spline interpolation coefficients are computed using MATLAB’s

`griddedInterpolant`function. Alternate interpolation methods can be set by either modifying line 6 by replacing ‘spline’ with ‘linear’ or ‘cubic’, or replacing it with an alternate interpolation algorithm, such as MATLAB’s

`spapi`function for higher order spline interpolation.

`griddedInterpolant`was used for computational efficiency.

`Xos`is displaced using the displacement SFPs from the previous correlation run, to track the same light intensity patterns within the reference subsets. These displacements SFPs are rounded, as suggested by Zhou et al. [53], such that the pixel positions of the reference subset have integer values and avoid the need for interpolating the reference subset.

`SubShapeExtract`to determine the data for a subset while

`SubCorr`uses this data to perform correlation of the subset. The loop can be implemented using parallel processing to reduce computation time by changing line 18 to a parfor-loop. However, during a parfor-loop the outputs of

`SubCorr`cannot be saved directly to a structure variable. It is for this reason that they are saved to the temporary storage variables (initiated in line 17) during the loop and assigned to

`PD`thereafter.

#### 3.2.2. `SubShapeExtract` Function

`SubShapeExtract`returns the data sets of ${\mathit{f}}_{i}$, $\nabla {\mathit{f}}_{i}$ and $\Delta {\mathit{x}}_{i}$ for a subset based on its intended shape, size and position, as outlined in Table 5. Note that these output data sets are in the form of vertical vectors. Alternative subset shapes can be added to this function provided they produce the same output data sets.

`SubExtract`is used to extract the appropriate elements from the input matrices ($F$ and $\nabla F$) which correspond to the pixels of the subset. $\Delta {\mathit{x}}_{i}$ is determined in line 7 according to

`SubSize`.

#### 3.2.3. `SubCorr` Function

`SubCorr`is at the heart of ADIC2D and performs the subset-based correlation, as summarised in Table 6. It follows the theoretical framework presented in Section 2.2.

#### 3.2.4. `SFExpressions` Function

`SFExpressions`returns five anonymous functions based on the SF order specified and is outlined in Table 7.

`W`, defines Equation (14),

`dFdWdP`defines $\nabla {\mathit{f}}_{i}\frac{\partial {\mathit{W}}_{i}}{\partial \mathit{P}}$,

`SFPVec2Mat`defines Equation (22),

`Mat2SFPVec`extracts $\mathit{P}$ from

`SFPVec2Mat`and

`StopCrit`defines Equation (23). Additional SFs, such as higher order polynomials, can be added after line 20 provided they are consistent with the outputs of

`SFExpressions`.

#### 3.2.5. `PCM` Function

`PCM`is efficient; however, it is limited to integer pixel displacements and can only use square subsets. Moreover,

`PCM`is only capable of determining a reliable initial estimate if the displacement is less than half of

`SubSize`. For more information on PCM, refer to the work of Foroosh et al. [54].

#### 3.3. `CSTrans` Function

`CSTrans`performs CS and displacement transformations from the distorted sensor CS to the world CS as outlined in Table 9.

`CSTrans`uses MATLAB’s image calibration toolbox to determine calibration parameters according to Section 2.1 which are used to perform the transformations detailed in Section 2.3. Note that the extrinsic calibration parameters, extracted in line 8, are based on the final set of CTs in the sensor CS (

`ImgCTs(:,:,end)`). Alternate calibration algorithms may be implemented by replacing lines 13 and 14.

## 4. Validation

`WorldCTs = 0`,

`ImageCTs = 0`and

`rho = 0`. A stopping criterion of

`StopCritVal = 10`, limited to 100 iterations per subset (line 12 in

^{−4}`SubCorr`), was used. The Gaussian image filter was set to

`FiltSize = 5`as this offers the best compromise between reducing bias and avoiding increasing variance [49].

`FiltSigma`is specified on a per sample basis.

#### 4.1. Quantifying Error

#### 4.2. Samples 1–3

`SubShape = ‘Circle’`,

`StepSize = 5`pixels,

`SFOrder = 1`and

`SubSize`to 21, 41 and 81 pixels. A

`FiltSigma`of 0.4, 0.8 and 0.6 was used for Samples 1, 2 and 3 respectively. Subsets of size 21, 41 and 81 pixels had 5000, 4500 and 3650 subsets per image respectively.

`SubSize = 21`has a 7% higher RMSE relative to Ncorr).

#### 4.3. Sample 14

`SubShape = ‘Square’`,

`StepSize`= 5, pixels,

`SFOrder`= 1,

`FiltSigma`= 0.4 and

`SubSize`to 25, 31, 51 and 71 pixels. A window of 9 measurement points was used to compute strain data. Table 14 shows the displacement and strain results in the x-direction, for the last image of the set, that were analysed using the MATLAB code provided by the DIC Challenge [39]. Codes A and G published in [39], which exhibit the best noise suppression (variance) and SR, respectively, are included for comparison. Subsets of size 25, 31, 51 and 71 pixels had 43,700, 43,700, 42,600 and 40,600 subsets per image.

`SubSize`= 25 pixels, the error metrics increase (except strain SR as illustrated in Figure 7b), indicating a limitation of ADIC2D with regards to noise suppression and SR for smaller subset sizes (as shown in Figure 7a). The strain SR does not increase because strain experiences more spatial filtering than displacement for the reasons outlined in the DIC Challenge paper [39]. Although ADIC2D cannot achieve results similar to code G, the results in Table 14 indicate that the noise suppression and SR are within the range of established DIC codes evaluated in the DIC Challenge paper [39].

## 5. Discussion

`ImgCorr`), the core correlation operations (

`SubCorr`), the effect of different SF orders on correlation (

`SFExpressions`), how data sets are prepared for different subset shapes (

`SubShapeExtract`) and determining initial estimates of the SFPs (

`PCM`) can be considered separately.

## 6. Conclusions

## Author Contributions

## Funding

## Acknowledgments

## Conflicts of Interest

## Abbreviations

$\alpha $ | Homogeneous scaling variable |

$\beta $ | Window size for the Gaussian filter |

${c}_{s}$ | Skew of sensor coordinate system (intrinsic camera parameter) |

${c}_{x},{c}_{y}$ | Translation applied to sensor coordinate system (intrinsic camera parameter) |

${C}_{ZNSSD}$ | Zero-mean normalised sum of squared difference correlation criterion |

${C}_{ZNCC}$ | Zero-mean normalised cross correlation criterion |

${C}_{ObjFun}$ | Objective function of correlation |

${E}_{proj}$ | Total projection error |

$F$ | Reference image |

$\mathit{f}$ | Reference subset |

$\overline{f}$ | Mean light intensity of reference subset |

$\tilde{f}$ | Normalisation function of reference subset |

$\nabla F$ | Light intensity gradient of the reference image |

$\nabla {\mathit{f}}_{i}=\left[\begin{array}{cc}\frac{\partial {f}_{i}}{\partial x}& \frac{\partial {f}_{i}}{\partial y}\end{array}\right]$ | Light intensity gradient of the reference subset |

$G$ | Deformed image |

$\mathit{g}$ | Investigated subset |

$\overline{g}$ | Mean light intensity of investigated subset |

$\tilde{g}$ | Normalisation function of investigated subset |

$\mathit{H}$ | Hessian of the optimisation equation |

$I$ | Number of pixels per subset (counter is $i$) |

$\mathit{J}$ | Jacobian of the optimisation equation |

$\mathit{K}$ | Intrinsic camera parameters |

${\kappa}_{1},{\kappa}_{2}$ | Radial distortion parameters |

$L$ | Number of calibration images (counter is $l$) |

$M$ | Number of calibration targets per calibration image (counter is $m$) |

$MA{E}_{u},MA{E}_{v}$ | Mean absolute error |

$\mathit{\omega}$ | Function to populate a square matrix with the shape function parameters |

$\psi $ | Stopping criterion value |

$\mathit{P}$ | Shape function parameters |

${\mathit{P}}_{update}$ | Updated shape function parameters |

$\Delta \mathit{P}$ | Iterative improvement estimate of the shape function parameters |

$Q$ | Number of subsets per an image (counter is $q$) |

$\mathit{R}$ | Rotation matrix |

$RMS{E}_{u},RMS{E}_{v}$ | Root mean square error |

$\rho $ | Calibration plate thickness |

${\sigma}^{g}$ | Standard deviation of the Gaussian function for Gaussian filtering |

${\sigma}_{u},{\sigma}_{v}$ | Variance (standard deviation of the absolute error) |

$t$ | Time |

$\mathit{T}$ | Translation vector |

${\mathit{T}}_{spec}$ | Translation vector corrected for the thickness of the calibration plate |

$u$ | Displacement in the x-direction in the distorted sensor coordinate system |

${u}^{true}$ | True displacement of subset in the x-direction in the distorted sensor coordinate system |

${u}^{calc}$ | Calculated displacement of subset in the x-direction in the distorted sensor coordinate system |

${\widehat{u}}_{w}$ | Undistorted metric displacement in the x-direction in the world coordinate system |

${u}_{x}$, ${u}_{y}$, ${u}_{xx}$, ${u}_{xy}$, ${u}_{yy}$ | Derivatives of the x-direction displacement |

$\mathit{V}$ | Extrinsic camera parameters |

$v$ | Displacement in the y-direction in the distorted sensor coordinate system |

${v}^{true}$ | True displacement of the subset in the y-direction in the distorted sensor coordinate system |

${v}^{calc}$ | Calculated displacement of the subset in the y-direction in the distorted sensor coordinate system |

${\widehat{v}}_{w}$ | Undistorted metric displacement in the y-direction in the world coordinate system |

${v}_{x}$, ${v}_{y}$, ${v}_{xx}$, ${v}_{xy}$, ${v}_{yy}$ | Derivatives of the y-direction displacement |

$\mathit{W}$ | Shape function |

$\frac{\partial {\mathit{W}}_{i}}{\partial \mathit{P}}$ | Jacobian of the shape function in terms of the shape function parameters for pixel $i$ |

${\widehat{\mathit{x}}}_{w}={\left[\begin{array}{ccc}{\widehat{x}}_{w}& {\widehat{y}}_{w}& {\widehat{z}}_{w}\end{array}\right]}^{T}$ | Ideal world coordinates |

${\widehat{\mathit{x}}}_{s}={\left[\begin{array}{cc}{\widehat{x}}_{s}& {\widehat{y}}_{s}\end{array}\right]}^{T}$ | Ideal sensor coordinates |

${\widehat{\mathit{x}}}_{n}={\left[\begin{array}{cc}{\widehat{x}}_{n}& {\widehat{y}}_{n}\end{array}\right]}^{T}$ | Normalized ideal image coordinates |

${\mathit{x}}_{n}={\left[\begin{array}{cc}{x}_{n}& {y}_{n}\end{array}\right]}^{T}$ | Normalized distorted image coordinates |

$\mathit{x}={\left[\begin{array}{cc}x& y\end{array}\right]}^{T}$ | Distorted sensor coordinates |

${\mathit{x}}^{true}={\left[\begin{array}{cc}{x}^{true}& {y}^{true}\end{array}\right]}^{T}$ | True location of the calibration targets in the distorted sensor coordinate system |

${\mathit{x}}^{calc}={\left[\begin{array}{cc}{x}^{calc}& {y}^{calc}\end{array}\right]}^{T}$ | Location of the calibration targets in the distorted sensor coordinate system predicted by the camera model |

${\mathit{x}}^{o}={\left[\begin{array}{cc}{x}^{o}& {y}^{o}\end{array}\right]}^{T}$ | Centre of reference subset in the distorted sensor coordinate system |

${\widehat{\mathit{x}}}^{o}={\left[\begin{array}{cc}{\widehat{x}}^{o}& {\widehat{y}}^{o}\end{array}\right]}^{T}$ | Centre of reference subset in the undistorted sensor coordinate system |

${\mathit{x}}^{d}={\left[\begin{array}{cc}{x}^{d}& {y}^{d}\end{array}\right]}^{T}$ | Centre of investigated subset in the distorted sensor coordinate system |

${\widehat{\mathit{x}}}^{d}={\left[\begin{array}{cc}{\widehat{x}}^{d}& {\widehat{y}}^{d}\end{array}\right]}^{T}$ | Centre of investigated subset in the undistorted sensor coordinate system |

${\mathit{x}}_{i}={\left[\begin{array}{cc}{x}_{i}& {y}_{i}\end{array}\right]}^{T}$ | $i$th pixel position of the reference subset in the distorted sensor coordinate system |

${\mathit{x}}_{i}^{\prime}={\left[\begin{array}{cc}{x}_{i}^{\prime}& {y}_{i}^{\prime}\end{array}\right]}^{T}$ | $i$th pixel position of the investigated subset in the distorted sensor coordinate system |

$\Delta {\mathit{x}}_{i}={\left[\begin{array}{cc}\Delta {x}_{i}& \Delta {y}_{i}\end{array}\right]}^{T}$ | Distance from the reference subset centre to $i$th pixel position of reference subset |

$\Delta {\mathit{x}}_{i}^{\prime}={\left[\begin{array}{cc}\Delta {x}_{i}^{\prime}& \Delta {y}_{i}^{\prime}\end{array}\right]}^{T}$ | Distance from the reference subset centre to $i$th pixel position of investigated subset |

${\widehat{\mathit{x}}}_{w}^{o}={\left[\begin{array}{cc}{\widehat{x}}_{w}^{o}& {\widehat{y}}_{w}^{o}\end{array}\right]}^{T}$ | Undistorted reference subset position in the world coordinate system |

${\widehat{\mathit{x}}}_{w}^{d}={\left[\begin{array}{cc}{\widehat{x}}_{w}^{d}& {\widehat{y}}_{w}^{d}\end{array}\right]}^{T}$ | Undistorted investigated subset position in the world coordinate system |

${\xi}_{x},{\xi}_{y}$ | Scaling of metric units to pixels (intrinsic camera parameter) |

$\zeta $ | Maximum distance of a pixel of the reference subset to the centre of the reference subset |

## Appendix A

1 function ProcData=ADIC2D(FileNames,Mask,GaussFilt,StepSize,SubSize, SubShape,SFOrder,RefStrat,StopCritVal,WorldCTs,ImgCTs,rho) 2 [~,ImNames]=cellfun(@fileparts,FileNames,’Uni’,0); 3 n=numel(FileNames); 4 [r,c]=size(im2double(imread(FileNames{1}))); 5 [XosX,XosY]=meshgrid(((SubSize+1)/2+StepSize):StepSize: (c-(SubSize+1)/2-1-StepSize),((SubSize+1)/2+StepSize): StepSize:(r-(SubSize+1)/2-1-StepSize)); 6 Xos=[XosX(:)’; XosY(:)’]; 7 Xos=Xos(:,arrayfun(@(X,Y) min(min(Mask(Y-(SubSize-1)/2:Y+(SubSize-1)/2,X-(SubSize-1)/2:X+(SubSize-1)/2))),Xos(1,:),Xos(2,:))==1); 8 ProcData=struct(’ImgName’,ImNames,’ImgSize’,repmat({[r,c]},1,n), ’ImgFilt’,repmat({GaussFilt},1,n),’SubSize’,repmat({SubSize*ones([1,size(Xos,2)])},1,n),’SubShape’,repmat({repmat(SubShape,size(Xos,2),1)},1,n),’SFOrder’,repmat({repmat(SFOrder,size(Xos,2),1)},1,n),’Xos’,repmat({Xos},1,n),’P’,repmat({zeros([12,size(Xos,2)])},1,n),’C’,repmat({ones([1,size(Xos,2)])},1,n),’StopVal’,repmat({ones([1,size(Xos,2)])*StopCritVal},1,n),’Iter’,repmat({zeros([1,size(Xos,2)])},1,n)); 9 ProcData=ImgCorr(n,ProcData,FileNames,RefStrat,StopCritVal); % Section 3.2.1 10 ProcData=CSTrans(n,ProcData,WorldCTs,ImgCTs,rho); % Section 3.3 1 function PD=ImgCorr(n,PD,ImNames,RefStrat,StopCritVal) 2 SubExtract=@(Mat,Xos,SubSize) Mat(Xos(2)-(SubSize-1)/2:Xos(2)+(SubSize-1)/2,Xos(1)-(SubSize-1)/2:Xos(1)+(SubSize-1)/2); 3 for d=2:n, tic; % outer loop 4 G=im2double(imread(ImNames{d})); 5 if all(PD(d).ImgFilt), G=imgaussfilt(G,PD(d).ImgFilt(1), ’FilterSize’,PD(d).ImgFilt(2)); end % Section 2.2.4 6 InterpCoef=griddedInterpolant({1:1:size(G,1),1:1:size(G,2)}, G,’spline’); % Section 2.2.3 7 if any([RefStrat==1,d==2]) 8 F=im2double(imread(ImNames{d-1})); 9 if all(PD(d).ImgFilt), F=imgaussfilt(F,PD(d).ImgFilt(1), ’FilterSize’,PD(d).ImgFilt(2)); end % Section 2.2.4 10 [dFdx,dFdy]=imgradientxy(F,’prewitt’); 11 PD(d).Xos(1,:)=PD(d-1).Xos(1,:)+fix(PD(d-1).P(1,:)); 12 PD(d).Xos(2,:)=PD(d-1).Xos(2,:)+fix(PD(d-1).P(7,:)); 13 [PD(d).P(1,:),PD(d).P(7,:)]=arrayfun(@(XosX,XosY,SubSize) PCM(F,G,SubSize,XosX,XosY,SubExtract),PD(d).Xos(1,:),PD(d).Xos(2,:),PD(d).SubSize); % Section 3.2.5 14 else 15 PD(d).P=PD(d-1).P; 16 end 17 P=zeros(size(PD(d).P)); C=zeros(size(PD(d).C)); Iter=zeros(size(PD(d).C)); StopVal=ones(size(PD(d).C)); 18 for q=1:size(PD(d).Xos,2) % inner loop (can be changed to parfor for parallel processing) 19 [f,dfdx,dfdy,dX,dY]=SubShapeExtract(PD(d).SubSize(q), PD(d).SubShape(q,:),PD(d).Xos(:,q),F,dFdx,dFdy,SubExtract); % Section 3.2.2 20 [P(:,q),C(q),Iter(q),StopVal(q)]=SubCorr(InterpCoef,f,dfdx, dfdy,PD(d).SubSize(q),PD(d).SFOrder(q),PD(d).Xos(:,q),dX,dY,PD(d).P(:,q),StopCritVal); % Section 3.2.3 21 end 22 PD(d).P=P; PD(d).C=C; PD(d).Iter=Iter; PD(d).StopVal=StopVal; 23 if rem(d-2,10)==0, fprintf(’Image/Total| Time (s) | CC (min) | CC (mean) | Iter (max) \n’); end 24 fprintf(’ %4.d/%4.d | %7.3f | %.6f | %.6f | %3.0f \n’,d,n,toc,min(PD(d).C),nanmean(PD(d).C),max(PD(d).Iter)); 25 end 1 function [f,dfdx,dfdy,dX,dY]=SubShapeExtract(SubSize,SubShape,Xos,F, dFdx,dFdy,SubExtract) 2 switch SubShape 3 case ’Square’ 4 f(:)=reshape(SubExtract(F,Xos,SubSize),[SubSize*SubSize,1]); 5 dfdx(:)=reshape(SubExtract(dFdx,Xos,SubSize), [SubSize*SubSize,1]); 6 dfdy(:)=reshape(SubExtract(dFdy,Xos,SubSize), [SubSize*SubSize,1]); 7 [dX,dY]=meshgrid(-(SubSize-1)/2:(SubSize-1)/2, -(SubSize-1)/2:(SubSize-1)/2); dX=dX(:); dY=dY(:); 8 case ’Circle’ 9 f=SubExtract(F,Xos,SubSize); 10 dfdx=SubExtract(dFdx,Xos,SubSize); 11 dfdy=SubExtract(dFdy,Xos,SubSize); 12 [dX,dY]=meshgrid(-(SubSize-1)/2:(SubSize-1)/2,-(SubSize-1)/2:(SubSize-1)/2); 13 mask_keep=sqrt(abs(dX).^2+abs(dY).^2)<=(SubSize/2-0.5); 14 f=f(mask_keep); 15 dfdx=dfdx(mask_keep); dfdy=dfdy(mask_keep); 16 dX=dX(mask_keep); dY=dY(mask_keep); 17 end 1 function [P,C,iter,StopVal]=SubCorr(InterpCoef,f,dfdx,dfdy,SubSize, SFOrder,Xos,dX,dY,P,StopCritVal) 2 [W,dFdWdP,SFPVec2Mat,Mat2SFPVec,StopCrit]=SFExpressions(SFOrder); % Section 3.2.4 3 dfdWdP=dFdWdP(dX(:),dY(:),dfdx(:),dfdy(:)); 4 Hinv=inv(dfdWdP’*dfdWdP); % inverse of Equation (20) 5 f_bar=mean(f(:)); f_tilde=sqrt(sum((f(:)-f_bar).^2)); 6 flag=0; iter=0; dP=ones(size(P)); 7 while flag==0 8 [dXY]=W(dX(:),dY(:),P); % Equation (14) 9 g=InterpCoef(Xos(2).*ones(size(dXY,1),1)+dXY(:,2), Xos(1).*ones(size(dXY,1),1)+dXY(:,1)); 10 g_bar=mean(g(:)); g_tilde=sqrt(sum((g(:)-g_bar).^2)); 11 StopVal=StopCrit(dP,(SubSize-1)/2); % Equation (23) 12 if any([StopVal<StopCritVal,iter>100]) 13 flag=1; 14 C=1-sum(((f(:)-f_bar)/f_tilde-(g(:)-g_bar)/g_tilde).^2)/2; % Equation (11) substituted into Equation (13) 15 else 16 J=dfdWdP’*(f(:)-f_bar-f_tilde/g_tilde*(g(:)-g_bar)); % Summation of Equation (19) 17 dP([1:SFOrder*3+0^SFOrder 7:6+SFOrder*3+0^SFOrder])= -Hinv*J; % Equation (19) 18 P=Mat2SFPVec(SFPVec2Mat(P)/SFPVec2Mat(dP)); % Equation (21) 19 end 20 iter=iter+1; 21 end 1 function [W,dFdWdP,SFPVec2Mat,Mat2SFPVec,StopCrit]= SFExpressions(SFOrder) 2 switch SFOrder 3 case 0 % Zero order SF 4 W=@(dX,dY,P) [P(1)+dX,P(7)+dY]; % Equation (14) 5 dFdWdP=@(dX,dY,dfdx,dfdy) [dfdx,dfdy]; 6 SFPVec2Mat=@(P) reshape([1,0,0,0,1,0,P(1),P(7),1],[3,3]); % Equation (22) 7 Mat2SFPVec=@(W) [W(7),0,0,0,0,0,W(8),0,0,0,0,0]; 8 StopCrit=@(dP,Zeta) sqrt(sum((dP’.*[1,0,0,0,0,0,1,0,0,0,0,0]) .^2)); % Equation (23) 9 case 1 % First order SF 10 W=@(dX,dY,P) [P(1)+P(3).*dY+dX.*(P(2)+1), P(7)+P(8).*dX+dY.*(P(9)+1)]; % Equation (14) 11 dFdWdP=@(dX,dY,dfdx,dfdy) [dfdx,dfdx.*dX,dfdx.*dY, dfdy,dfdy.*dX,dfdy.*dY]; 12 SFPVec2Mat=@(P) reshape([P(2)+1,P(8),0,P(3),P(9)+1,0,P(1), P(7),1],[3,3]); % Equation (22) 13 Mat2SFPVec=@(W) [W(7),W(1)-1.0,W(4),0,0,0,W(8),W(2), W(5)-1.0,0,0,0]; 14 StopCrit=@(dP,Zeta) sqrt(sum((dP’.*[1,Zeta,Zeta,0,0,0,1,Zeta, Zeta,0,0,0]).^2)); % Equation (23) 15 case 2 % Second order SF 16 W=@(dX,dY,P) [P(1)+P(3).*dY+P(4).*dX.^2.*(1/2)+P(6).*dY.^2.* (1/2)+dX.*(P(2)+1)+P(5).*dX.*dY,P(7)+P(8).*dX+P(10).*dX.^2.*(1/2)+P(12).*dY.^2.*(1/2)+dY.*(P(9)+1)+P(11).*dX.*dY]; % Equation (14) 17 dFdWdP=@(dX,dY,dfdx,dfdy) [dfdx,dfdx.*dX,dfdx.*dY, (dfdx.*dX.^2)/2,dfdx.*dX.*dY,(dfdx.*dY.^2)/2,dfdy,dfdy.*dX,dfdy.*dY,(dfdy.*dX.^2)/2,dfdy.*dX.*dY,(dfdy.*dY.^2)/2]; 18 SFPVec2Mat=@(P) reshape([P(2)*2+P(1)*P(4)+P(2)^2+1, P(1)*P(10)*1/2+P(4)*P(7)*(1/2)+P(8)*(P(2)*2+2)*1/2,P(7)*P(10)+P(8)^2,P(4)*1/2,P(10)*1/2,0,P(1)*P(5)*2+P(3)*(P(2)*2+2),P(2)+P(9)+P(2)*P(9)+P(3)*P(8)+P(1)*P(11)+P(5)*P(7)+1,P(7)*P(11)*2.0+P(8)*(P(9)+1)*2,P(5),P(11),0,P(1)*P(6)+P(3)^2,P(1)*P(12)*1/2+P(6)*P(7)*1/2+P(3)*(P(9)+1),P(9)*2+P(7)*P(12)+P(9)^2+1,P(6)*1/2,P(12)*1/2,0,P(1)*(P(2)+1)*2,P(7)+P(1)*P(8)+P(2)*P(7),P(7)*P(8)*2,P(2)+1,P(8),0,P(1)*P(3)*2,P(1)+P(1)*P(9)+P(3)*P(7),P(7)*(P(9)+1)*2,P(3),P(9)+1,0,P(1)^2,P(1)*P(7),P(7)^2,P(1),P(7),1],[6,6]); % Equation (22) 19 Mat2SFPVec=@(W) [W(34),W(22)-1,W(28),W(4).*2,W(10),W(16).*2, W(35),W(23),W(29)-1,W(5).*2,W(11),W(17).*2]; 20 StopCrit=@(dP,Zeta) sqrt(sum((dP’.*[1,Zeta,Zeta,0.5*Zeta, 0.5*Zeta,0.5*Zeta,1,Zeta,Zeta,0.5*Zeta,0.5*Zeta,0.5*Zeta]).^2)); % Equation (23) 21 end 1 function [u,v]=PCM(F,G,SubSize,XosX,XosY,SubExtract) 2 NCPS=(fft2(SubExtract(F,[XosX,XosY],SubSize)) .*conj(fft2(SubExtract(G,[XosX,XosY],SubSize))))./abs(fft2(SubExtract(F,[XosX,XosY],SubSize)).*conj(fft2(SubExtract(G,[XosX,XosY],SubSize)))); 3 CC=abs(ifft2(NCPS)); 4 [vid,uid]=find(CC==max(CC(:))); 5 IndShift=-ifftshift(-fix(SubSize/2):ceil(SubSize/2)-1); 6 u=IndShift(uid); 7 v=IndShift(vid); 1 function PD=CSTrans(n,PD,WorldCTs,ImgCTs,rho) 2 if WorldCTs~=0 | ImgCTs~=0 3 CamParams=estimateCameraParameters(ImgCTs,WorldCTs); % Section 2.1.4 4 else 5 CamParams=cameraParameters(’ImageSize’,PD(1).ImgSize, ’IntrinsicMatrix’,eye(3),’WorldPoints’,PD(1).Xos’,’RotationVectors’,[0,0,0],’TranslationVectors’,[0,0,0]); 6 WorldCTs=PD(1).Xos’; ImgCTs=PD(1).Xos’; 7 end 8 [R,T]=extrinsics(ImgCTs(:,:,end),WorldCTs,CamParams); 9 Tspec=T-[0,0,rho]*R; % Equation (6) 10 for d=1:n 11 Xds(1,:)=PD(d).Xos(1,:)+PD(d).P(1,:); % Equation (24) 12 Xds(2,:)=PD(d).Xos(2,:)+PD(d).P(7,:); % Equation (24) 13 PD(d).Xow=pointsToWorld(CamParams,R,Tspec, undistortPoints(PD(d).Xos’,CamParams))’; 14 Xdw=pointsToWorld(CamParams,R,Tspec, undistortPoints(Xds’,CamParams))’; 15 PD(d).Uw=Xdw-PD(d).Xow; % Equation (26) 16 PD(d).CamParams=CamParams; 17 end

## References

- Pan, B.; Qian, K.; Xie, H.; Asundi, A. Two-dimensional digital image correlation for in-plane displacement and strain measurement: A review. Meas. Sci. Technol.
**2009**, 20, 062001. [Google Scholar] [CrossRef] - Pan, B. Digital image correlation for surface deformation measurement: Historical developments, recent advances and future goals. Meas. Sci. Technol.
**2018**, 29, 082001. [Google Scholar] [CrossRef] - Shao, X.; Dai, X.; Chen, Z.; He, X. Real-time 3D digital image correlation method and its application in human pulse monitoring. Appl. Opt.
**2016**, 55, 696–704. [Google Scholar] [CrossRef] - Lin, D.; Zhang, A.; Gu, J.; Chen, X.; Wang, Q.; Yang, L.; Chou, Y.; Liu, G.; Wang, J. Detection of multipoint pulse waves and dynamic 3D pulse shape of the radial artery based on binocular vision theory. Comput. Methods Programs Biomed.
**2018**, 155, 61–73. [Google Scholar] [CrossRef] [PubMed] - Tuononen, A.J. Digital Image Correlation to analyse stick-slip behaviour of tyre tread block. Tribol. Int.
**2014**, 69, 70–76. [Google Scholar] [CrossRef] - Sutton, M.A.; Ke, X.; Lessner, S.M.; Goldbach, M.; Yost, M.; Zhao, F.; Schreier, H.W. Strain field measurements on mouse carotid arteries using microscopic three-dimensional digital image correlation. J. Biomed. Mater. Res. Part A
**2008**, 84, 178–190. [Google Scholar] [CrossRef] - Palanca, M.; Tozzi, G.; Cristofolini, L. The use of digital image correlation in the biomechanical area: A review. Int. Biomech.
**2016**, 3, 1–21. [Google Scholar] [CrossRef] - Zhang, D.; Arola, D.D. Applications of digital image correlation to biological tissues. J. Biomed. Opt.
**2004**, 9, 691–700. [Google Scholar] [CrossRef] - Winkler, J.; Hendy, C. Improved structural health monitoring of London’s Docklands Light Railway bridges using Digital image correlation. Struct. Eng. Int.
**2017**, 27, 435–440. [Google Scholar] [CrossRef] - Reagan, D.; Sabato, A.; Niezrecki, C. Feasibility of using digital image correlation for unmanned aerial vehicle structural health monitoring of bridges. Struct. Health Monit.
**2018**, 17, 1056–1072. [Google Scholar] [CrossRef] - LeBlanc, B.; Niezrecki, C.; Avitabile, P.; Chen, J.; Sherwood, J. Damage detection and full surface characterization of a wind turbine blade using three-dimensional digital image correlation. Struct. Health Monit.
**2013**, 12, 430–439. [Google Scholar] [CrossRef] - Molina-Viedma, A.J.; Felipe-Sesé, L.; López-Alba, E.; Díaz, F.A. 3D mode shapes characterisation using phase-based motion magnification in large structures using stereoscopic DIC. Mech. Syst. Signal Process.
**2018**, 108, 140–155. [Google Scholar] [CrossRef] - Barone, S.; Neri, P.; Paoli, A.; Razionale, A.V. Low-frame-rate single camera system for 3D full-field high-frequency vibration measurements. Mech. Syst. Signal Process.
**2019**, 123, 143–152. [Google Scholar] [CrossRef] - Bickel, V.T.; Manconi, A.; Amann, F. Quantitative assessment of digital image correlation methods to detect and monitor surface displacements of large slope instabilities. Remote Sens.
**2018**, 10, 865. [Google Scholar] [CrossRef][Green Version] - Walter, T.R.; Legrand, D.; Granados, H.D.; Reyes, G.; Arámbula, R. Volcanic eruption monitoring by thermal image correlation: Pixel offsets show episodic dome growth of the Colima volcano. J. Geophys. Res. Solid Earth
**2013**, 118, 1408–1419. [Google Scholar] [CrossRef][Green Version] - Leprince, S.; Barbot, S.; Ayoub, F.; Avouac, J.P. Automatic and precise orthorectification, coregistration, and subpixel correlation of satellite images, application to ground deformation measurements. IEEE Trans. Geosci. Remote Sens.
**2007**, 45, 1529–1558. [Google Scholar] [CrossRef][Green Version] - Heid, T.; Kääb, A. Evaluation of existing image matching methods for deriving glacier surface displacements globally from optical satellite imagery. Remote Sens. Environ.
**2012**, 118, 339–355. [Google Scholar] [CrossRef] - Wang, P.; Pierron, F.; Thomsen, O.T. Identification of material parameters of PVC foams using digital image correlation and the virtual fields method. Exp. Mech.
**2013**, 53, 1001–1015. [Google Scholar] [CrossRef] - Grédiac, M.; Pierron, F.; Surrel, Y. Novel procedure for complete in-plane composite characterization using a single T-shaped specimen. Exp. Mech.
**1999**, 39, 142–149. [Google Scholar] [CrossRef] - Huchzermeyer, R. Measuring Mechanical Properties Using Digital Image Correlation: Extracting Tensile and Fracture Properties from A Single Sample. Master’s Thesis, Stellenbosch University, Stellenbosch, South Africa, 2017. [Google Scholar]
- Leclerc, H.; Périé, J.N.; Roux, S.; Hild, F. Integrated digital image correlation for the identification of mechanical properties. In Proceedings of the International Conference on Computer Vision/Computer Graphics Collaboration Techniques and Applications, Rocquencourt, France, 4–6 May 2009; Gagalowic, A., Philips, W., Eds.; Springer: Heidelberg/Berlin, Germany, 2009; pp. 161–171. [Google Scholar]
- Chevalier, L.; Calloch, S.; Hild, F.; Marco, Y. Digital image correlation used to analyze the multiaxial behavior of rubber-like materials. Eur. J. Mech. A Solids
**2001**, 20, 169–187. [Google Scholar] [CrossRef][Green Version] - van Rooyen, M.; Becker, T.H. High-temperature tensile property measurements using digital image correlation over a non-uniform temperature field. J. Strain Anal. Eng. Des.
**2018**, 53, 117–129. [Google Scholar] [CrossRef] - Peters, W.H.; Ranson, W.F. Digital imaging techniques in experimental stress analysis. Opt. Eng.
**1982**, 21, 427–431. [Google Scholar] [CrossRef] - Peters, W.H.; Ranson, W.F.; Sutton, M.A.; Chu, T.C.; Anderson, J. Application of digital correlation methods to rigid body mechanics. Opt. Eng.
**1983**, 22, 738–742. [Google Scholar] [CrossRef] - Chu, T.C.; Ranson, W.F.; Sutton, M.A. Applications of digital-image-correlation techniques to experimental mechanics. Exp. Mech.
**1985**, 25, 232–244. [Google Scholar] [CrossRef] - Sutton, M.; Mingqi, C.; Peters, W.; Chao, Y.; McNeill, S. Application of an optimized digital correlation method to planar deformation analysis. Image Vis. Comput.
**1986**, 4, 143–150. [Google Scholar] [CrossRef] - Bruck, H.A.; McNeill, S.R.; Sutton, M.A.; Peters, W.H. Digital image correlation using newton-raphson method of partial differential correction. Exp. Mech.
**1989**, 29, 261–267. [Google Scholar] [CrossRef] - Luo, P.F.; Chao, Y.J.; Sutton, M.A.; Peters, W.H. Accurate measurement of three-dimensional deformations in deformable and rigid bodies using computer vision. Exp. Mech.
**1993**, 33, 123–132. [Google Scholar] [CrossRef] - Bay, B.K.; Smith, T.S.; Fyhrie, D.P.; Saad, M. Digital volume correlation: Three-dimensional strain mapping using X-ray tomography. Exp. Mech.
**1999**, 39, 217–226. [Google Scholar] [CrossRef] - Schreier, H.W.; Braasch, J.R.; Sutton, M.A. Systematic errors in digital image correlation caused by intensity interpolation. Opt. Eng.
**2000**, 39, 2915–2921. [Google Scholar] [CrossRef] - Lu, H.; Cary, P.D. Deformation measurements by digital image correlation: Implementation of a second-order displacement gradient. Exp. Mech.
**2000**, 40, 393–400. [Google Scholar] [CrossRef] - Baker, S.; Matthews, I. Lucas-kanade 20 years on: A unifying framework. Int. J. Comput. Vis.
**2004**, 56, 221–255. [Google Scholar] [CrossRef] - Tong, W. An evaluation of digital image correlation criteria for strain mapping applications. Strain
**2005**, 41, 167–175. [Google Scholar] [CrossRef] - Pan, B.; Li, K.; Tong, W. Fast, robust and accurate digital image correlation calculation without redundant computations. Exp. Mech.
**2013**, 53, 1277–1289. [Google Scholar] [CrossRef] - Gao, Y.; Cheng, T.; Su, Y.; Xu, X.; Zhang, Y.; Zhang, Q. High-efficiency and high-accuracy digital image correlation for three-dimensional measurement. Opt. Lasers Eng.
**2015**, 65, 73–80. [Google Scholar] [CrossRef] - Pan, B.; Wang, B. Digital image correlation with enhanced accuracy and efficiency: A comparison of two subpixel registration algorithms. Exp. Mech.
**2016**, 56, 1395–1409. [Google Scholar] [CrossRef] - Blaber, J.; Adair, B.; Antoniou, A. Ncorr: Open-source 2D digital image correlation matlab software. Exp. Mech.
**2015**, 55, 1105–1122. [Google Scholar] [CrossRef] - Reu, P.L.; Toussaint, E.; Jones, E.; Bruck, H.A.; Iadicola, M.; Balcaen, R.; Turner, D.Z.; Siebert, T.; Lava, P.; Simonsen, M. DIC challenge: Developing images and guidelines for evaluating accuracy and resolution of 2D analyses. Exp. Mech.
**2018**, 58, 1067–1099. [Google Scholar] [CrossRef] - Bloomenthal, J.; Rokne, J. Homogeneous coordinates. Vis. Comput.
**1994**, 11, 15–26. [Google Scholar] [CrossRef] - Zhang, Z. A flexible new technique for camera calibration. IEEE Trans. Pattern Anal. Mach. Intell.
**2000**, 22, 1330–1334. [Google Scholar] [CrossRef][Green Version] - Heikkila, J.; Silven, O. Four-step camera calibration procedure with implicit image correction. In Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition, San Juan, PR, USA, 17–19 June 1997. [Google Scholar]
- Tsai, R.Y. A versatile camera calibration technique for high-accuracy 3D machine vision metrology using off-the-shelf TV cameras and lenses. IEEE J. Robot. Autom.
**1987**, 3, 323–344. [Google Scholar] [CrossRef][Green Version] - Wei, G.Q.; De Ma, S. Implicit and explicit camera calibration: Theory and experiments. IEEE Trans. Pattern Anal. Mach. Intell.
**1994**, 16, 469–480. [Google Scholar] [CrossRef] - Pan, B.; Xie, H.; Wang, Z. Equivalence of digital image correlation criteria for pattern matching. Appl. Opt.
**2010**, 49, 5501–5509. [Google Scholar] [CrossRef][Green Version] - Keys, R.G. Cubic convolution interpolation for digital image processing. IEEE Trans. Acoust.
**1981**, 29, 1153–1160. [Google Scholar] [CrossRef][Green Version] - Hou, H.S.; Andrews, H.C. Cubic splines for image interpolation and digital filtering. IEEE Trans. Acoust.
**1978**, 26, 508–517. [Google Scholar] [CrossRef] - Pan, Z.; Chen, W.; Jiang, Z.; Tang, L.; Liu, Y.; Liu, Z. Performance of global look-up table strategy in digital image correlation with cubic B-spline interpolation and bicubic interpolation. Theor. Appl. Mech. Lett.
**2016**, 6, 126–130. [Google Scholar] [CrossRef][Green Version] - Pan, B. Bias error reduction of digital image correlation using gaussian pre-filtering. Opt. Lasers Eng.
**2013**, 51, 1161–1167. [Google Scholar] [CrossRef] - Pan, B.; Xie, H.; Wang, Z.; Qian, K.; Wang, Z. Study on subset size selection in digital image correlation for speckle patterns. Opt. Express
**2008**, 16, 7037–7048. [Google Scholar] [CrossRef] - Żołądek, H. The topological proof of abel-ruffini theorem. Topol. Methods Nonlinear Anal.
**2000**, 16, 253–265. [Google Scholar] [CrossRef] - Pan, B.; Asundi, A.; Xie, H.; Gao, J. Digital image correlation using iterative least squares and pointwise least squares for displacement field and strain field measurements. Opt. Lasers Eng.
**2009**, 47, 865–874. [Google Scholar] [CrossRef] - Zhou, Y.; Sun, C.; Chen, J. Adaptive subset offset for systematic error reduction in incremental digital image correlation. Opt. Lasers Eng.
**2014**, 55, 5–11. [Google Scholar] [CrossRef] - Foroosh, H.; Zerubia, J.B.; Berthod, M. Extension of phase correlation to subpixel registration. IEEE Trans. Image Process.
**2002**, 11, 188–200. [Google Scholar] [CrossRef] [PubMed][Green Version] - Orteu, J.-J.; Garcia, D.; Robert, L.; Bugarin, F. A speckle texture image generator. In Proceedings of the Speckle06: Speckles, From Grains to Flowers, Nîmes, France, 13–15 September 2006; Slangen, P., Cerruti, C., Eds.; SPIE: Bellingham, WA, USA, 2006; pp. 104–109. [Google Scholar]
- Reu, P.L. Experimental and numerical methods for exact subpixel shifting. Exp. Mech.
**2011**, 51, 443–452. [Google Scholar] [CrossRef] - Bornert, M.; Brémand, F.; Doumalin, P.; Dupré, J.C.; Fazzini, M.; Grédiac, M.; Hild, F.; Mistou, S.; Molimard, J.; Orteu, J.J.; et al. Assessment of digital image correlation measurement errors: Methodology and results. Exp. Mech.
**2009**, 49, 353–370. [Google Scholar] [CrossRef][Green Version] - Amiot, F.; Bornert, M.; Doumalin, P.; Dupré, J.C.; Fazzini, M.; Orteu, J.J.; Poilâne, C.; Robert, L.; Rotinat, R.; Toussaint, E.; et al. Assessment of digital image correlation measurement accuracy in the ultimate error regime: Main results of a collaborative benchmark. Strain
**2013**, 49, 483–496. [Google Scholar] [CrossRef][Green Version] - Harilal, R.; Ramji, M. Adaptation of open source 2D DIC software ncorr for solid mechanics applications. In Proceedings of the 9th International Symposium on Advanced Science and Technology in Experimental Mechanics, New Delhi, India, 1–6 November 2014. [Google Scholar]
- Lunt, D.; Thomas, R.; Roy, M.; Duff, J.; Atkinson, M.; Frankel, P.; Preuss, M.; Quinta da Fonseca, J. Comparison of sub-grain scale digital image correlation calculated using commercial and open-source software packages. Mater. Charact.
**2020**, 163, 110271. [Google Scholar] [CrossRef] - Pan, B. Reliability-guided digital image correlation for image deformation measurement. Appl. Opt.
**2009**, 48, 1535–1542. [Google Scholar] [CrossRef] [PubMed] - Schreier, H.W.; Sutton, M.A. Systematic errors in digital image correlation due to undermatched subset shape functions. Exp. Mech.
**2002**, 42, 303–310. [Google Scholar] [CrossRef]

**Figure 1.**Schematic diagram illustrating how the camera model is comprised of the pinhole camera model and radial distortion model.

**Figure 2.**Schematic diagram illustrating how the pixel positions of the reference and investigated subsets are related to one another within the distorted sensor CS.

**Figure 3.**Schematic diagram illustrating the allowable deformation of a subset for various SF orders.

**Figure 4.**Graphical representation of the interpolation equations for: (

**a**) linear polynomial; (

**b**) cubic polynomial; and (

**c**) cubic b-spline interpolation methods.

**Figure 6.**Comparison of the x-displacement for Sample 14 for a subset size of: (

**a**) 25 pixels; and (

**b**) 51 pixels.

**Figure 7.**Comparison of the noise suppression (variance) and SR for various subset sizes in terms of: (

**a**) displacement; and (

**b**) strain results.

Variable | Variable Description |
---|---|

FileNames | Cell array of character vectors containing the image file names of the image set d. All images need to be the same size. |

Mask | Logical matrix, which is the same size as the images, indicating which pixels should not be analysed during correlation. |

GaussFilt | Define the standard deviation and window size for the Gaussian filter in pixels as [FiltSigma, FiltSize] respectively where {FiltSigma ∈ ℝ^{+}|FiltSigma > 0} and {FiltSize ∈ ℕ}. |

StepSize | Step size in pixels {StepSize ∈ ℕ}. |

SubSize | Subset size in pixels {SubSize = 2k + 1|k ∈ ℕ}. |

SubShape | Subset shape {SubShape ∈ ‘Square’, ‘Circle’}. |

SFOrder | Dictates the SF order {SFOrder ∈ ℤ|0 ≤ SFOrder ≤ 2}. |

RefStrat | Logical statement dictating reference image strategy (Section 3.2). |

StopCritVal | Defines the stopping criterion value {StopCritVal ∈ ℝ^{+}|StopCritVal > 0}. |

WorldCTs | Location of CTs in the world CS defined according to MATLAB’s estimateCameraParameters function. |

ImgCTs | Location of CTs in the sensor CS defined according to MATLAB’s estimateCameraParameters function. |

rho | Calibration plate thickness in millimetres. |

Variable | Variable Description |
---|---|

ImgName | Image name. |

ImgSize(b) | Image size (b = 1 for rows and b = 2 for columns). |

ImgFilt(b) | Standard deviation (b = 1) and window size (b = 2) for the Gaussian filter respectively in pixels. |

SubSize(q) | Subset size in pixels. |

SubShape(q) | Subset shape. |

SFOrder(q) | SF order. |

Xos(b,q) | Reference subset position in the distorted sensor CS (b = 1 for ${x}^{o}$ and b = 2 for ${y}^{o}$). |

Xow(b,q) | Reference subset position in the world CS (b = 1 for ${\widehat{x}}_{w}^{o}$ and b = 2 for ${\widehat{y}}_{w}^{o}$). |

P(b,q) | SFPs (b = 1 for $u$ and b = 7 for $v$). |

C(q) | ZNCC coefficient. |

Uw(b,q) | Displacement in the world CS (b = 1 for ${\widehat{u}}_{w}$ and b = 2 for ${\widehat{v}}_{w}$). |

Iter(q) | Number of iterations until stopping criterion is satisfied (maximum of 100 iterations). |

CamParams | Calibration parameters. |

Line Numbers | Task Performed |
---|---|

Lines 2–4 | Compute image names, number of images and size of the first image; |

Lines 5–6 | Create regularly spaced reference subset positions, Xos; |

Line 7 | Remove subsets containing invalid pixels which are defined by Mask; |

Line 8 | Pre-assign ProcData structure; |

Line 9 | Call subroutine ImgCorr to perform image correlation; |

Line 10 | Call subroutine CSTrans to perform transformation from the distorted sensor CS to the world CS; |

Line Numbers | Task Performed |
---|---|

Line 2 | Define SubExtract function to extract square subset data; |

Line 3 | for image number d = 2 to d = n, do |

Line 4 | Define G |

Line 5 | Perform Gaussian filtering on G using MATLAB’s imgaussfilt function; |

Line 6 | Compute interpolation coefficients using MATLAB’s griddedInterpolant function; |

Line 7 | if first image of correlation run or Refstrat is incremental, do |

Line 8 | Define F; |

Line 9 | Perform Gaussian filtering on F using MATLAB’s imgaussfilt function; |

Line 10 | Compute gradients for F (compute $\nabla F$); |

Lines 11–12 | Displace Xos with previous image correlation run displacements (incremental strategy); |

Line 13 | Call subroutine PCM to compute initial estimates of displacement SFPs; |

Line 14 | else, do |

Line 15 | Set P(d) ← P(d − 1); |

Line 16 |
end if |

Line 17 | Initialise temporary storage variables used to save correlation information during the inner loop; |

Line 18 | for subset number q = 1 to number of subsets, do |

Line 19 | Call subroutine SubShapeExtract; |

Line 20 | Call subroutine SubCorr; |

Line 21 | end for |

Line 22 | Save correlation information to PD variable; |

Line 23–24 | Show results for image d correlation; |

Line 25 | end for |

Line Numbers | Task Performed |
---|---|

Line 2 | switch SubShape; |

Line 3 | case SubShape = ‘Square’, do |

Line 4–6 | Extract ${\mathit{f}}_{i}$$\mathrm{and}\nabla {\mathit{f}}_{i}$ using SubExtract; |

Line 7 | Compute $\Delta {\mathit{x}}_{i}$ using SubSize; |

Line 8 | case SubShape = ‘Circle’, do |

Line 9–11 | Extract ${\mathit{f}}_{i}$$\mathrm{and}\nabla {\mathit{f}}_{i}$ using SubExtract; |

Line 12 | Compute $\Delta {\mathit{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 |

Line Numbers | Task Performed |
---|---|

Line 2 | Call SFExpressions to assign equations dependent on the SF order; |

Line 3 | $\mathrm{Compute}\nabla {\mathit{f}}_{i}\frac{\partial {\mathit{W}}_{i}}{\partial \mathit{P}}$; |

Line 4 | Compute ${\mathit{H}}^{\mathbf{-}\mathbf{1}}$, Equation (20); |

Line 5 | Compute normalisation values $\overline{f}$ and $\tilde{f}$; |

Line 6 | Initialise flag ← 0, iter ← 0 and $\Delta \mathit{P}\leftarrow 1$; |

Line 7 | while flag = 0, do |

Line 8 | Compute
$\Delta {\mathit{x}}_{i}^{\prime}$ Equation (14), using estimates of P |

Line 9 | Compute g using interpolation coefficients; |

Line 10 | Compute normalisation values $\overline{g}$ and $\tilde{g}$; |

Line 11 | Compute ‖ΔP‖using Equation (23); |

Line 12 | if ‖ΔP‖ < StopCritVal or iter > 100, do |

Line 13 | Set iter ← 1; |

Line 14 | Compute C, Equation (11) substituted into Equation (13); |

Line 15 | else, do |

Line 16 | Compute J, Summation expression of Equation (19); |

Line 17 | Compute ΔP, Equation (19); |

Line 18 | Update P, Equation (21); |

Line 19 |
end if |

Line 20 | Set iter ← iter + 1 |

Line 21 | end while |

Line Numbers | Task Performed |
---|---|

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 |

Line Numbers | Task Performed |
---|---|

Line 2 | Compute normalised cross-power spectrum in the frequency domain; |

Line 3 | Convert back to spatial domain; |

Line 4 | Find index of the maximum correlation coefficient; |

Line 5 | Compute index vector which relates indices of the correlation coefficient matrix to the displacements they correspond to; |

Line 6–7 | Obtain displacements using index of the maximum correlation coefficient; |

Line Numbers | Task Performed |
---|---|

Line 2 | if calibration targets are given, do |

Line 3 | Compute calibration parameters using MATLAB’s estimateCameraParameters function; |

Line 4 | else, do |

Line 5 | Set unit calibration parameters and pass to MATLAB’s cameraParameters function; |

Line 6 | Assign CTs in the distorted sensor and world CSs using Xos; |

Line 7 | end if |

Line 8 | Extract appropriate extrinsic parameters; |

Line 9 | Compute ${\mathit{T}}_{spec}$, Equation (6); |

Line 10 | for image number d = 1 to d = n, do |

Lines 11–12 | Compute ${\mathit{x}}_{d}$, Equation (24); |

Line 13–14 | Compute ${\mathit{x}}_{w}^{o}$ and ${\mathit{x}}_{w}^{d}$ using MATLAB’s undistortPoints and pointsToWorld functions; |

Line 15 | Compute ${\widehat{u}}_{w}$ and ${\widehat{v}}_{w}$, Equation (26); |

Line 16 | Save calibration parameters; |

Line 17 | end for |

**Table 10.**Details for the samples of the DIC Challenge [39].

Name | Method | Noise | Contrast | Images | Displacement field |
---|---|---|---|---|---|

Sample 1 | TexGen | 1.5 | Varying | 21 | Shift of 0.05 pixels in both directions per image |

Sample 2 | TexGen | 8 | 0–50 | 21 | Shift of 0.05 pixels in both directions per image |

Sample 3 | Fourier | 1.5 | 0–200 | 12 | Shift of 0.1 pixels in both directions per image |

Sample 14 | Fourier | 5 | 0–200 | 4 | Sinusoid in the x-direction of increasing frequency (amplitude 0.1 pixels) |

Code | Subset Size 21 | Subset Size 41 | Subset Size 81 | ||||||
---|---|---|---|---|---|---|---|---|---|

Bias | Variance | RMSE | Bias | Variance | RMSE | Bias | Variance | RMSE | |

ADIC2D | 2.32 | 2.59 | 3.48 | 1.08 | 0.88 | 1.4 | 0.634 | 0.481 | 0.796 |

Ncorr | 2.31 | 2.63 | 3.5 | 0.995 | 0.822 | 1.29 | 0.504 | 0.402 | 0.645 |

DaVis | 1.34 | 1.05 | 1.7 | 0.652 | 0.497 | 0.819 | 0.317 | 0.246 | 0.401 |

Code | Subset Size 21 | Subset Size 41 | Subset Size 81 | ||||||
---|---|---|---|---|---|---|---|---|---|

Bias | Variance | RMSE | Bias | Variance | RMSE | Bias | Variance | RMSE | |

ADIC2D | 3.49 | 4.24 | 5.5 | 1.16 | 0.917 | 1.48 | 0.519 | 0.391 | 0.65 |

Ncorr | 5.59 | 5.96 | 8.17 | 2.05 | 1.71 | 2.67 | 0.956 | 0.759 | 1.22 |

DaVis | 1.84 | 1.57 | 2.42 | 0.781 | 0.599 | 0.985 | 0.377 | 0.281 | 0.47 |

Code | Subset Size 21 | Subset Size 41 | Subset Size 81 | ||||||
---|---|---|---|---|---|---|---|---|---|

Bias | Variance | RMSE | Bias | Variance | RMSE | Bias | Variance | RMSE | |

ADIC2D | 9.75 | 8.17 | 12.7 | 3.77 | 2.9 | 4.76 | 1.87 | 1.4 | 2.34 |

Ncorr | 9.18 | 7.58 | 11.9 | 3.97 | 3.05 | 5.01 | 2.36 | 1.7 | 2.91 |

DaVis | 5.16 | 4.02 | 6.54 | 2.47 | 1.9 | 3.12 | 1.29 | 1 | 1.64 |

**Table 14.**Sample 14 error analysis in the x-direction for last image of the image set [39].

Code/Subset Size | Displacement | Strain | ||||||
---|---|---|---|---|---|---|---|---|

RMSE (pix) | Variance (pix) | Max Bias (pix) | SR (pix) | RMSE (pix/pix) | Variance (pix/pix) | Max Bias (pix/pix) | SR (pix) | |

Code G | 0.010 | 0.010 | 0.012 | 100 | 453 | 429 | 923 | 74 |

ADIC2D 25 | 0.018 | 0.017 | 0.015 | 1629 | 598 | 406 | 1488 | 173 |

ADIC2D 31 | 0.014 | 0.013 | 0.017 | 160 | 600 | 335 | 1674 | 182 |

ADIC2D 51 | 0.014 | 0.007 | 0.033 | 257 | 839 | 193 | 2720 | 233 |

ADIC2D 71 | 0.022 | 0.005 | 0.059 | 354 | 1255 | 125 | 4412 | 294 |

Code A | 0.022 | 0.005 | 0.056 | 716 | 1131 | 172 | 3399 | 410 |

© 2020 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Atkinson, D.; Becker, T.
A 117 Line 2D Digital Image Correlation Code Written in MATLAB. *Remote Sens.* **2020**, *12*, 2906.
https://doi.org/10.3390/rs12182906

**AMA Style**

Atkinson D, Becker T.
A 117 Line 2D Digital Image Correlation Code Written in MATLAB. *Remote Sensing*. 2020; 12(18):2906.
https://doi.org/10.3390/rs12182906

**Chicago/Turabian Style**

Atkinson, Devan, and Thorsten Becker.
2020. "A 117 Line 2D Digital Image Correlation Code Written in MATLAB" *Remote Sensing* 12, no. 18: 2906.
https://doi.org/10.3390/rs12182906