original = rgb2gray(imread('A0.png'));
ptsOriginal = detectSURFFeatures(original,'NumOctaves',1,'NumScaleLevels',5,'MetricThreshold',10);
[featuresOriginal,validPtsOriginal] = extractFeatures(original,ptsOriginal);
figure
distorted = rgb2gray(imread(sprintf('A2.png',k)));
subplot(121), imshowpair(original,distorted,'m'),
ptsDistorted = detectSURFFeatures(distorted,'NumOctaves',1,'NumScaleLevels',5,'MetricThreshold',5);
[featuresDistorted,validPtsDistorted] = extractFeatures(distorted,ptsDistorted);
indexPairs = matchFeatures(featuresOriginal,featuresDistorted);
matchedOriginal = validPtsOriginal(indexPairs(:,1));
matchedDistorted = validPtsDistorted(indexPairs(:,2));
[tform, inlierDistorted,inlierOriginal] = ...
estimateGeometricTransform(matchedDistorted,...
matchedOriginal,'similarity');
outputView = imref2d(size(original));
recovered = imwarp(distorted,tform,'OutputView',outputView);
subplot(122), imshowpair(original,recovered)