1
votes

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).

And i thought i could use SURF Features to accomplish this. Here's the code:

source = imread('source.png');
target = imread('target.png');
source = rgb2gray(source);
target = rgb2gray(target);

sourcePoints=detectSURFFeatures(source,'MetricThreshold',100.0,'NumOctaves',1,'NumScaleLevels',6);
targetPoints=detectSURFFeatures(target,'MetricThreshold',100.0,'NumOctaves',1,'NumScaleLevels',6);

%figure; imshow(source);
%hold on;
%plot(sourcePoints.selectStrongest(10000));


[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), :);

figure;
showMatchedFeatures(source, target, matchedSourcePoints, matchedTargetPoints, 'montage');

display(matchedSourcePoints);
display(matchedTargetPoints);

The problem is that from what i know you have functions that only display matched SURF Points, and i would need to plot on the target image only the points that didn't match with the points in the source image.

The resulting "matchedTargetPoints" and the "targetPoints" variables are arrays of SURFPoints objects, so the find function doesn't work, subtracting or making array operations on them don't work. I also tried to loop through "targetPoints" and check for every one if the point exists, but the script takes forever, so this also doesn't work.

Does anyone have any idea how this might be accomplished? Any response is appreciated.

Thank you.

1

1 Answers

1
votes

You can get the (x,y) locations of the points stored in an M-by-2 matrix by using the Location property of the SURFPoints object. Then you can get the unmatched points using logical indexing:

targetPointsLoc = targetPoints.Location;
unmatchedIdx = true(size(targetPoitnsLoc, 1), 1);
unmatchedIdx(boxPairs(:, 2)) = false;
unmatchedTargetPoints = targetPointsLoc(unmatchedIdx, :);

Now you can use plot to display the unmatched points.

Out of curiosity, why do you care about the unmatched points?