Clear Filters
Clear Filters

Image Rotation and Scale Using Automated Feature Matching

2 views (last 30 days)
I try to derive
Image Rotation and Scale Using Automated Feature Matching
I use the code provided by Matlab
My code is:
% thinning image
Image1= imread('i1.bmp');
J1=edge(Image1,'canny',0.1);% 'Canny Finds edges by looking for local maxima of the gradient of J. The edge function calculates the gradient using the derivative of a Gaussian filter. This method uses two thresholds to detect strong and weak edges, including weak edges in the output if they are connected to strong edges. By using two thresholds, the Canny method is less likely than the other methods to be fooled by noise, and more likely to detect true weak edges.BW = edge(I,method,threshold) returns all edges that are stronger than threshold.
% figure;
% imshow(J1);
J2 = bwareaopen(J1, 30);
% figure;
% imshow(J2);
J2( ~any(J2,2), : ) = []; %rows
J2( :, ~any(J2,1) ) = []; %columns
figure;
imshow(J2);
Image2= imread('i3.bmp');
J3=edge(Image2,'canny',0.1);% 'Canny Finds edges by looking for local maxima of the gradient of J. The edge function calculates the gradient using the derivative of a Gaussian filter. This method uses two thresholds to detect strong and weak edges, including weak edges in the output if they are connected to strong edges. By using two thresholds, the Canny method is less likely than the other methods to be fooled by noise, and more likely to detect true weak edges.BW = edge(I,method,threshold) returns all edges that are stronger than threshold.
% figure;
% imshow(J3);
J4 = bwareaopen(J3, 30);
% figure;
% imshow(J4);
J4( ~any(J4,2), : ) = []; %rows
J4( :, ~any(J4,1) ) = []; %columns
figure;
imshow(J4);
% matrix dimensions must be of same length.
% https://in.mathworks.com/help/vision/ug/find-image-rotation-and-scale-using-automated-feature-matching.html
ptsJ2 = detectSURFFeatures(J2);
ptsJ4 = detectSURFFeatures(J4);
[featuresJ2, validPtsJ2] = extractFeatures(J2, ptsJ2);
[featuresJ4, validPtsJ4] = extractFeatures(J4, ptsJ4);
indexPairs = matchFeatures(featuresJ2, featuresJ4);
matchedJ2 = validPtsJ2(indexPairs(:,1));
matchedJ4 = validPtsJ4(indexPairs(:,2));
figure;
showMatchedFeatures(J2,J4,matchedJ2,matchedJ4);
title('Putatively matched points (including outliers)');
[tform, inlierIdx] = estimateGeometricTransform(matchedJ4, matchedJ2, 'similarity');
inlierJ4 = matchedJ4(inlierIdx, :); % error is in this line
inlierJ2 = matchedJ2(inlierIdx, :);
figure;
showMatchedFeatures(J2,J4,inlierJ2,inlierJ4);
title('Matching points (inliers only)');
legend('ptsJ2','ptsJ4');
Tinv = tform.invert.T;
ss = Tinv(2,1);
sc = Tinv(1,1);
scaleRecovered = sqrt(ss*ss + sc*sc);
thetaRecovered = atan2(ss,sc)*180/pi;
outputView = imref2d(size(J2));
recovered = imwarp(J4,tform,'OutputView',outputView);
figure, imshowpair(J2,recovered,'montage')
buut is gives an error of ::::
Function 'subsindex' is not defined for values of class 'SURFPoints'.
error line is also mentioned in code.
please help me to retireve its solution.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!