diff --git a/skimage/feature/match.py b/skimage/feature/match.py index d9f95c90..4093c6b6 100644 --- a/skimage/feature/match.py +++ b/skimage/feature/match.py @@ -5,8 +5,7 @@ from .match_cy import _binary_cross_check_loop def match_binary_descriptors(keypoints1, descriptors1, keypoints2, - descriptors2, threshold=0.40, cross_check=True, - return_mask=True): + descriptors2, threshold=0.40, cross_check=True): """Match keypoints described using binary descriptors in one image to those in second image. @@ -15,30 +14,28 @@ def match_binary_descriptors(keypoints1, descriptors1, keypoints2, keypoints1 : (M, 2) ndarray M Keypoints from the first image described using skimage.feature.brief descriptors1 : (M, P) ndarray - BRIEF descriptors of size P about M keypoints in the first image. + Binary descriptors of size P about M keypoints in the first image. keypoints2 : (N, 2) ndarray N Keypoints from the second image described using skimage.feature.brief descriptors2 : (N, P) ndarray - BRIEF descriptors of size P about N keypoints in the second image. + Binary descriptors of size P about N keypoints in the second image. threshold : float in range [0, 1] Maximum allowable hamming distance between descriptors of two keypoints in separate images to be regarded as a match. cross_check : bool - Cross check if True. - return_mask : bool - Return index masks mask1 and mask2 for matched keypoints from - keypoints1 and keypoints2 respectively. + If True, the matched keypoints are returned after cross checking i.e. a + matched pair (keypoint1, keypoint2) is returned iff keypoint2 is the best + match for keypoint1 in second image and keypoint1 is the best match for + keypoint2 in first image. Returns ------- - match_keypoints_pairs : (Q, 2, 2) ndarray + matches : (Q, 2, 2) ndarray Location of Q matched keypoint pairs from two images. mask1 : (Q,) ndarray - Indices of keypoints in keypoints1 that have been matched. Returned - only when return_mask is True. + Indices of keypoints in keypoints1 that have been matched. mask2 : (Q,) ndarray - Indices of keypoints in keypoints2 that have been matched. Returned - only when return_mask is True. + Indices of keypoints in keypoints2 that have been matched. """ if (keypoints1.shape[0] != descriptors1.shape[0] @@ -61,28 +58,22 @@ def match_binary_descriptors(keypoints1, descriptors1, keypoints2, matched_keypoints2_index, distance, threshold) - matched_keypoint_pairs = np.zeros((matched_index.shape[0], 2, 2), + matches = np.zeros((matched_index.shape[0], 2, 2), dtype=np.intp) mask1 = matched_index[:, 0] mask2 = matched_index[:, 1] - matched_keypoint_pairs[:, 0, :] = keypoints1[mask1] - matched_keypoint_pairs[:, 1, :] = keypoints2[mask2] - if return_mask: - return (matched_keypoint_pairs, mask1, mask2) - else: - return matched_keypoint_pairs + matches[:, 0, :] = keypoints1[mask1] + matches[:, 1, :] = keypoints2[mask2] else: temp = distance > threshold row_check = np.any(~temp, axis=1) matched_keypoints2 = keypoints2[np.argmin(distance, axis=1)] - matched_keypoint_pairs = np.zeros((np.sum(row_check), 2, 2), + matches = np.zeros((np.sum(row_check), 2, 2), dtype=np.intp) - matched_keypoint_pairs[:, 0, :] = keypoints1[row_check] - matched_keypoint_pairs[:, 1, :] = matched_keypoints2[row_check] + matches[:, 0, :] = keypoints1[row_check] + matches[:, 1, :] = matched_keypoints2[row_check] mask1 = np.where(row_check == True) mask2 = np.argmin(distance, axis=1)[row_check] - if return_mask: - return (matched_keypoint_pairs, mask1, mask2) - else: - return matched_keypoint_pairs + + return matches, mask1, mask2 diff --git a/skimage/feature/match_cy.pyx b/skimage/feature/match_cy.pyx index 8a1bb461..6574d573 100644 --- a/skimage/feature/match_cy.pyx +++ b/skimage/feature/match_cy.pyx @@ -5,15 +5,12 @@ def _binary_cross_check_loop(Py_ssize_t[:] matched_keypoints1_index, Py_ssize_t[:] matched_keypoints2_index, double[:, ::1] distance, double threshold): cdef Py_ssize_t i - #matched_index = [] - cdef Py_ssize_t count = 0 cdef Py_ssize_t[:, ::1] matched_index = np.zeros((len(matched_keypoints1_index), 2), dtype=np.intp) for i in range(len(matched_keypoints1_index)): if (matched_keypoints2_index[matched_keypoints1_index[i]] == i and distance[i, matched_keypoints1_index[i]] < threshold): - #matched_index.append([i, matched_keypoints1_index[i]]) matched_index[count, 0] = i matched_index[count, 1] = matched_keypoints1_index[i] count += 1 diff --git a/skimage/feature/orb_cy.pyx b/skimage/feature/orb_cy.pyx index e312f95b..e7197797 100644 --- a/skimage/feature/orb_cy.pyx +++ b/skimage/feature/orb_cy.pyx @@ -9,7 +9,7 @@ import numpy as np from libc.math cimport sin, cos, M_PI, round -pos = np.loadtxt("skimage/feature/orb_descriptor_positions.txt", dtype=np.int8) +pos = np.loadtxt("orb_descriptor_positions.txt", dtype=np.int8) pos0 = np.ascontiguousarray(pos[:, :2]) pos1 = np.ascontiguousarray(pos[:, 2:])