# Stereo Digital Image Correlation in MATLAB
## 6 Conclusions
[dFdx,dFdy]=imgradientxy(F, 'prewitt');
9. P=FeatureMatch(RD.ProData1,1,F,G,SubExtract); % Section 3.3.2
10. C=NaN(1,size(P,2)); Iter=NaN(1,size(P,2)); StopVal=NaN(1,size(P,2));
11. for q=1:size(P,2) % can be changed to parfor for parallel processing
12. if (sum(isnan(P(:,q)))==0)&&(sum(isnan(RD.ProData1(1).Xos (:,q))) ==0)
13. [f,dfdx,dfdy,dX,dY]=SubShapeExtract( RD.ProData1(1). SubSize(q), RD.ProData1(1).Xos(:,q), F,dfdx,dfdy, SubExtract); % Section 3.2
14. [Pout(:,q),C(q),Iter(q),StopVal(q)]=SubCorr(InterpCoef, fdfdx, dfdy,RD. ProData1(1).SubSize(q), RD.ProData1(1).SFOrder(q),RD.ProData1(1). Xos(:,q),dX, dY,P(:,q), StopCritVal); % Section 3.2
15. end
16. end
17. RD.Stereo.P=Pout; RD.Stereo.C=C; RD.Stereo.Iter=Iter; RD.Stereo. StopVal=StopVal;
18. for d=1:n % determine subset positions in the FIS2 using Equation (32)
19. RD.ProData2(d).Xos(1,:)=RD.ProData2(d). [PERSON](1,:)+ round(RD.Stereo. P(1,:)); RD.ProData2(d).Xos(2,:)= RD.ProData2(d).Xos(2,:)+round(RD. Stereo.P(7,:));
20. end
21. FailedSubsetsCondition=(RD.Stereo.C=0.6)==0|(RD.ProData2(1). [PERSON] (1,:)+(RD.ProProData2(1).SubSize(:)'-1)/2>size(G,2))| (RD.ProData2(1). [PERSON](1,:)-(RD.ProData2(1).SubSize(:)'-1)/2<1) |(RD.ProData2(1).[PERSON](2,:)+(RD.ProData2(1).SubSize(:)'-1)/2>size(G,1))|(RD.ProData2(1). [PERSON](2,:)-(RD.ProData2(1).SubSize(:)'-1)/2<1);
22. FailedSubsets=find(FailedSubsetsCondition); PassedSubsets=find (FailedSubsetsCondition==0);
23. for d=1:n24. RD.ProCData1(d).Xos(:,FailedSubsets)=NaN(2,size(FailedSubsets,2));
25. RD.ProCData2(d).Xos(:,FailedSubsets)=NaN(2,size(FailedSubsets,2));
26. end
27. fprintf('Stereo results\t| Time (s)| CC (min)| CC (mean)| Iter (max) \
\t\t\t| t\t| %7.3f| %.5f| %.6f| %4.Of \
Subsets that failed stereo matching %d/%d\
',toc,min(RD. Stereo.C(PassedSubsets)),annean(RD.Stereo.C(PassedSubsets)),max(RD. Stereo.Iter( PassedSubsets)),size(FailedSubsets,2),size(P,2));
1. function [P]=FeatureMatch(PD,d,F,G,SubExtract)
2. if exist('vl_sift')~3, fprintf('\
Error occurred, please setup the VLFeat library required for SIFT feature matching (algorithm can be found at: [[https://www.vlfeat.org_n](https://www.vlfeat.org_n)]([https://www.vlfeat.org_n](https://www.vlfeat.org_n))'); end; time_before_sift=toc;
3. [xk1,d1] = v1_sift(im2 single(uint8(255*F)));
4. [xk2,d2] = v1_sift(im2 single(uint8(255*G)));
5. KptsInVacinity=((abs(PD(d).Xos(2,:)-xk1(2,:)')<=PD(d).SubSize/2)+ (abs(PD(d).Xos(1,:)-xk1(1,:)')<=PD(d).SubSize/2))==2;
6. xk1=xk1(:,sum(KptsInVacinity,2)>=1); d1=d1(:,sum(KptsInVacinity,2)>=1);
7. [matches, scores] = v1_ubcmatch(d1, d2,1.25);
8. xk1=xk1(1:2,matches(1,:))'; xk2=xk2(1:2,matches(2,:))';
9. relevantKpts=knnsearch(xk1,PD(d).Xos','K',20);
10. RansacModel=@(kpts[Kpts(:,1)kpts(:,2)ones(size(kpts(:,1),1),1)] \kpts(:,3)-[1;0;0];[kpts(:,1)kpts(:,2)ones(size(kpts(:,1),1),1)] \kpts(:,4)-[0;1;0]]; % solves for affine transformation parameters of Equation (29)
11. RansacError=@(a, kpts) sum((kpts(:,3:4)'-[1+a(1), a(2), a(3); a(4), 1+ a(5), a(6)]*[kpts(:,1)';kpts(:,2)';ones(1, size(kpts(:,1)',2))]). ~2,1); % Equation(30)
12. P=NaN(12,size(PD(d).Xos,2));
13. for q=1:size(PD(d).Xos,2) % can be changed to parfor for parallel processing
14. try
15. [a,'] = ransac([xk1(relevantKpts(q,:),:),xk2( relevantKpts(q,:),:)], @(data) RansacModel(data), @(model,data) RansacError(model,data), 3,1, Confidence',99;);
16. P(:,q)=[a(1)*PD(d).Xos(1,q)+a(2)*PD(d).Xos(2,q)+a(3); a(1); a(2);
0;0;0a(4)PD(d).Xos(1,q)+a(5)*PD(d).Xos(2,q)+a(6);4(4);a(5);0;0;0];% Equation (31)
17. end
18. end
19. fprintf('SIFT found %d matching keypoints in %5.2f seconds\
',size (matches,2),toc-time_before_sift);
1. function [u,v]=PCM(F,G,SubSize,XosX,XosY,SubExtract)
2. if (isnan(XosX)==0)&&(isnan(XosY)==0)
3. 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))));
4. CC=(fft2(NCPS));
5. [vid,uid]=find(CC==max(CC(:)));
6.