diff --git a/skimage/feature/__init__.py b/skimage/feature/__init__.py index 1f7c960b..8b33d6c7 100644 --- a/skimage/feature/__init__.py +++ b/skimage/feature/__init__.py @@ -12,6 +12,7 @@ from .template import match_template from ._brief import brief, match_keypoints_brief from .util import pairwise_hamming_distance from .censure import keypoints_censure +from .orb import keypoints_orb, descriptor_orb __all__ = ['daisy', 'hog', @@ -36,4 +37,6 @@ __all__ = ['daisy', 'structure_tensor', 'structure_tensor_eigvals', 'hessian_matrix', - 'hessian_matrix_eigvals'] + 'hessian_matrix_eigvals', + 'keypoints_orb', + 'descriptor_orb'] diff --git a/skimage/feature/orb.py b/skimage/feature/orb.py index 009d1276..f6b4e01c 100644 --- a/skimage/feature/orb.py +++ b/skimage/feature/orb.py @@ -3,6 +3,39 @@ import numpy as np from ..util import img_as_float from .util import _mask_border_keypoints +from skimage.feature import corner_fast, corner_orientations, corner_peaks +from skimage.transform import pyramid_gaussian + + +def keypoints_orb(image, n=9, threshold=0.20, downscale_factor=1.414, + n_scales=5): + + image = np.squeeze(image) + if image.ndim != 2: + raise ValueError("Only 2-D gray-scale images supported.") + + pyramid = list(pyramid_gaussian(image, n_scales - 1, downscale_factor)) + + ofast_mask = np.array([[0, 0, 1, 1, 1, 0, 0], + [0, 1, 1, 1, 1, 1, 0], + [1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1], + [0, 1, 1, 1, 1, 1, 0], + [0, 0, 1, 1, 1, 0, 0]], dtype=np.uint8) + + keypoints = np.empty((0, 2), dtype=np.intp) + orientations = np.empty((0), dtype=np.double) + scales = np.empty((0), dtype=np.intp) + + for i in range(n_scales): + corners = corner_peaks(corner_fast(pyramid[i], n, threshold), min_distance=1) + keypoints = np.vstack((keypoints, corners)) + orientations = np.hstack((orientations, corner_orientations(pyramid[i], corners, ofast_mask))) + scales = np.hstack((scales, i * np.ones((corners.shape[0]), dtype=np.intp))) + + return keypoints, orientations, scales + def descriptor_orb(image, keypoints, keypoints_angle):