Why matchFeatures gives two different answers?

5 次查看(过去 30 天)
I tried to run this code:
I1 = rgb2gray(imread('viprectification_deskLeft.png'));
I2 = rgb2gray(imread('viprectification_deskRight.png'));
points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);
[features1, valid_points1] = extractFeatures(I1, points1);
[features2, valid_points2] = extractFeatures(I2, points2);
indexPairs1 = matchFeatures(features1, features2);
indexPairs2 = matchFeatures(features2, features1);
My Question: Why indexPairs1 and indexPairs2 have different length? I suppose it share the same length rite?

采纳的回答

Anand
Anand 2013-4-9
They are not expected to share the same length. The first tries to find the best matches for features1 in features2 and the second tries to find the best matches for features2 in features1.
For the nearest neighbor ratio matching method (the default), this plays out as follows:
Assume features1 has 100 features and features2 has 200.
In the case of matchFeatures(features1,features2), for each of the 100 features in features1, the top 2 matches (2 nearest neighbors) from the 200 features in features2 are found. This gives us 100 pairs of 2 features each. These are then accepted or rejected by seeing whether the distance ratio between the nearest neighbor and the second nearest neighbor.
The process I described above is not symmetric. So, you can expect that matchFeatures(features2,features1) maybe slightly different.
You can look at this paper for details about this: K. Mikolajczyk and C. Shmid, "A Performance Evaluation of Local Descriptors," IEEE PAMI, 27, 10 (2005)
If you would like symmetric matches, try the 'NearestNeighborSymmetric' method:
indexPairs1 = matchFeatures(features1,features2,'Method','NearestNeighborSymmetric');
indexPairs2 = matchFeatures(features2,features1,'Method','NearestNeighborSymmetric');
>> isequal(fliplr(sort(indexPairs2)),sort(indexPairs1))
ans =
1
  2 个评论
Elena Ranguelova
Elena Ranguelova 2016-11-4
Unfortunately this method is not available anymore in the current (latest) version (MATLAB 2016b). Now the options for 'Method' are only Exhaustive' or 'Approximate'.
How can one perform symmetric matching?
Morten Beier
Morten Beier 2017-8-20
It's long time ago Elena posted, but maybe someone else needs an answer :-) To make the sets match so indexPairs1 and indexPairs2 are of equal length you can use 'unique' meaning that each match is unique - also known as the 'marriage problem' (A needs to match B, but B also needs to match A). For example:
indexPairs = matchFeatures(features1,features2,'Unique',true);
matchedPoints1 = valid_corners1(indexPairs(:,1),:);
matchedPoints2 = valid_corners2(indexPairs(:,2),:);

请先登录,再进行评论。

更多回答(1 个)

Zainor
Zainor 2013-4-9
Thank you Anand for the answer

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by