Created
July 22, 2019 14:41
-
-
Save mihaidusmanu/20fd0904b2102acc1330bad9b4badab8 to your computer and use it in GitHub Desktop.
Mutual NN Matcher (numpy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def mutual_nn_matcher(descriptors1, descriptors2): | |
descriptors1 = descriptors1 / np.linalg.norm(descriptors1, axis=1)[:, np.newaxis] | |
descriptors2 = descriptors2 / np.linalg.norm(descriptors2, axis=1)[:, np.newaxis] | |
similarity = descriptors1 @ descriptors2.transpose() | |
nn12 = np.argmax(similarity, axis=1) | |
nn21 = np.argmax(similarity, axis=0) | |
ids1 = np.arange(similarity.shape[0]) | |
valid_matches = (ids1 == nn21[nn12]) | |
return np.vstack([ | |
ids1[valid_matches], nn12[valid_matches] | |
]).transpose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment