# Using SURF algorithm to match objects on MATLAB

I am trying to find the difference between two images, using Matlab. The classic built in function that Matlab provides for this is because the two images don't have the same dimensions (The objects in the images are the same, but in the second image other objects are introduced). i need to use a metric or function can calculate the number of matching feature between two images and give me a value to decide according to threshold ..

source = imread('source.png');
source = rgb2gray(source);
target = rgb2gray(target);
sourcePoints=detectSURFFeatures(source,'MetricThreshold',100.0,'NumOctaves',1,'N   umScaleLevels',6);
targetPoints=detectSURFFeatures(target,'MetricThreshold',100.0,'NumOctaves',1,'NumScaleLevels',6);
[sourceFeatures,sourcePoints]=extractFeatures(source,sourcePoints,'SURFSize',64);
[targetFeatures,targetPoints]=extractFeatures(target,targetPoints,'SURFSize',64);

boxPairs = matchFeatures(sourceFeatures, targetFeatures);

matchedSourcePoints = sourcePoints(boxPairs(:, 1), :);
matchedTargetPoints = targetPoints(boxPairs(:, 2), :);

% IS there any metric can used to make accurate decision if there is a match or not instead of percentage because its not accurate as required
numPairs = length(boxpairs); %the number of pairs
percentage  = numPairs/100;

if percentage >= 0.40
disp('We have this');
else
disp('We do not have this');
disp(percentage);
end


IS there any metric can used to make accurate decision if there is a match or not instead of percentage because its not accurate as required

• Use feature detection and extraction from your reference frame to create kernels for 2D cross correlation on the remaining frame. Then decide on threshold, scoring logic to define a match. Start with a noise free, simple object frames to set thresholds, scoring numbers. Jul 7, 2015 at 19:10

You can try estimating a geometric transformation between the matched sets of features using estimateGeometricTransform. The number of inliers returned by the function could be used to decide whether an object is present. See this example.