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');
target = imread('target.png');
source = rgb2gray(source);
target = rgb2gray(target);
  sourcePoints=detectSURFFeatures(source,'MetricThreshold',100.0,'NumOctaves',1,'N   umScaleLevels',6);

  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');
     disp('We do not have this');

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

  • $\begingroup$ 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. $\endgroup$ – docscience Jul 7 '15 at 19:10

People generally use Euclidean distances, just like you do and it works as it is, pretty well. However, if you require further robustness, I propose the following:

  1. Compute the matching both ways: image1->image2 and image2->image and then retrieve only the agreeing matches. This introduces some consensus.
  2. Assuming you have planar patches, you run a homography using RANSAC. The good thing here is that RANSAC is robust to outliers, given a predifined tolerance. This way prune away a lot of matches, and you will be left with a meaningful set of inliers.

Using these two together should really give you robust and repeatable matches.

| improve this answer | |
  • $\begingroup$ thank you for your replay , if possible you can suggest me code to apply these things as you mention , i need your help in this manner how i can apply these things in my code and make decision according to 1st and 2nd points ,,, thanks sir $\endgroup$ – azifallail Jul 7 '15 at 9:58

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.

| improve this answer | |
  • $\begingroup$ thank you for your replay ,,, after i applied this function and eliminate outliers i need to calculate the inlier Points for my source and target .. is there any function can calculate these points ,, and i can put a metric for example if these inliers >= number based on how many strongest point i put ,, i need to decide rather than plot square around object , thanks again $\endgroup$ – azifallail Jul 8 '15 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.