# Stereo Digital Image Correlation in MATLAB
## 6 Conclusions
[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 [W,dFdWdP,SFPVec2 Mat,Mat2 SFPVec,StopCrit]= SFExpression (SFOrder)
2. switch SFOrder
3. case 0 % Zero order SF
4. w=0(dX,dY,P) [P(1)+dX,P(7)+dY]; % Equation (9)
5. dFdWdP=@(dX,dY,dfdx,dfdy) [dfdx,dfdy];6.SFPVec2 Mat=@(P) reshape([1,0,0,0,1,0,P(1),P(7),1],[3,3]); % Equation (22) 7.Mat2 SFPVec=@(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 (9) 11.dFWdP=@(dX,dY,dfdx,dfdy) [dfdx,dfdx.*dX,dfdx.*dY,dfdy,dfdy. *dX, dfdy. *dY]; 12.SFPVec2 Mat=@(P) reshape([P(2)+1,P(8),0,P(3),P(9)+1,0,P(1),P(7),1], [3,3]); % Equation (22) 13.Mat2 SFPVec=@(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. *(P(9)+1)+ P(11).*dX. *dY]; % Equation (9) 17.dFWdP=@(dX,dY,dfdx,dfdy) [dfdx,dfdx.*dX,dfdx. *dY, (dfdx. *dX.^2)/2, dfdx.*dX. *dY, (dfdx. *dY.^2)/2, dfdy.*dX. *dY, (dfdy. *dX.^2)/2, 18.SFPVec2 Mat=@(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)*(12)+P(6)*P(7)*1/2+P(3)*(P(9)+1),P(9)*2+P(7)* P (12)+P(9)^2+1,P(6)*P(12)*1/2,P(12)*1/2,0,P(1)*(P(2)+1)*2,P(7) +P(1)*P(8)+P(2) *P(7)*P(8)*P,P(2)+1,P(8),0,P(1)*P(3)*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.Mat2 SFPVec=@(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.^2,Zeta.^2,Zeta.^2,0.5*Zeta.^2,0.5*Zeta.^2]).^2)); % Equation (23) 21.end
1.function[P,C,Iter,StopVal]=SubCorr(InterpCoef,f,dfdx,dfdy,SubSize, SFOrder,Xos,dX,dY,P,StopCritVal)
2. [W,dFdWdP,SFPVec2 Mat,Mat2 SFPVec,StopCrit]=SFExpressions( SFOrder); % Section 3.dfWdP=dFWdP@(dX:),dY(:),dfdx(:),dfdy(:)); 4.Hinv=inv(dfWdP*dfWdP); % inverse of Equation (19) 5.f_bar=mean(f(:)); f_tilde=sqrt(sum((f(:)-f_bar).^2)); % Equations (13) and (14) 6.flag=0; Iter=1; dP=ones(size(P)); 7.while flag==0 8. [dXY]=W(dX(:),dY(:),P); % Equation (7) 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)); % Equations (13) and (14) 11.StopVal=StopCrit(dP,(SubSize-1)/2); % Equation (23) 12.ifany([StopVal<StopCritVal,Iter>=100])13. flag=1;
14. C=1-sum(((f(:)-f_bar)/f_tilde-(g(:)-g_bar)/g_tilde).^2) /2; % Equation (12) substituted into Equation (15)
15. else
16. J=dfdfdfdf0'*(f(:)-f_bar-f_tilde/g_tilde*(g(:)-g_bar)); % Summation of Equation (18)
17. dP([1:SFOrder*3+0^SFOrder 7:6+SFOrder*3+0^SFOrder])=-Hinv*J; % Equation (18)
18. P=Mat2 SFPVec(SFPVec2 Mat(P)/SFPVec2 Mat(dP)); % Equation (21)
19. end
20. Iter=Iter+1;
21. end
1. function RD=StereoMatch(n,RD,ImNames1,ImNames2,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); tic;
3. F=in2 double(imread(ImNames1{1}));
4. if all(RD.ProData1(1).ImgFilt), F=imagaussfilt(F, RD.ProData1(1). ImgFilt(1),'FilterSize', RD.ProData1(1). ImgFilt(2)); end
5. G=in2 double(imread(ImNames2{1}));
6. if all(RD.ProData1(1).ImgFilt), G=imagaussfilt(G, RD.ProData1(1). ImgFilt(1),'FilterSize', RD.ProData1(1). ImgFilt(2)); end
7. InterpCoef=griddedInterpolant({1:1:size(G,1),1:1:size(G,2)}, G,'spline');
8.