mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 09:36:32 +08:00
Extending recarray changes to BRIEF
This commit is contained in:
committed by
Johannes Schönberger
parent
38bdd3e523
commit
1a2efa7e37
@@ -11,7 +11,7 @@ from .corner_cy import corner_moravec, corner_orientations
|
||||
from .template import match_template
|
||||
from ._brief import descriptor_brief
|
||||
from .match import match_binary_descriptors
|
||||
from .util import pairwise_hamming_distance
|
||||
from .util import pairwise_hamming_distance, create_keypoint_recarray
|
||||
from .censure import keypoints_censure
|
||||
from .orb import keypoints_orb, descriptor_orb
|
||||
|
||||
@@ -31,6 +31,7 @@ __all__ = ['daisy',
|
||||
'match_template',
|
||||
'descriptor_brief',
|
||||
'pairwise_hamming_distance',
|
||||
'create_keypoint_recarray',
|
||||
'match_binary_descriptors',
|
||||
'keypoints_censure',
|
||||
'corner_fast',
|
||||
|
||||
@@ -17,8 +17,9 @@ def descriptor_brief(image, keypoints, descriptor_size=256, mode='normal',
|
||||
----------
|
||||
image : 2D ndarray
|
||||
Input image.
|
||||
keypoints : (P, 2) ndarray
|
||||
Array of keypoint locations in the format (row, col).
|
||||
keypoints : record array with P rows
|
||||
Record array with fields row, col, octave, orientation, response.
|
||||
Octave, orientation and response can be None.
|
||||
descriptor_size : int
|
||||
Size of BRIEF descriptor about each keypoint. Sizes 128, 256 and 512
|
||||
preferred by the authors. Default is 256.
|
||||
@@ -141,15 +142,18 @@ def descriptor_brief(image, keypoints, descriptor_size=256, mode='normal',
|
||||
|
||||
image = np.ascontiguousarray(image)
|
||||
|
||||
keypoints = np.array(keypoints + 0.5, dtype=np.intp, order='C')
|
||||
keypoints_loc = np.array(np.squeeze(np.dstack((keypoints.row, keypoints.col)))
|
||||
+ 0.5, dtype=np.intp, order='C')
|
||||
|
||||
# Removing keypoints that are within (patch_size / 2) distance from the
|
||||
# image border
|
||||
keypoints = keypoints[_mask_border_keypoints(image, keypoints, patch_size // 2)]
|
||||
keypoints = np.ascontiguousarray(keypoints)
|
||||
border_mask = _mask_border_keypoints(image, keypoints_loc, patch_size // 2)
|
||||
keypoints = keypoints[border_mask]
|
||||
keypoints_loc = keypoints_loc[border_mask]
|
||||
keypoints_loc = np.ascontiguousarray(keypoints_loc)
|
||||
|
||||
descriptors = np.zeros((keypoints.shape[0], descriptor_size), dtype=bool,
|
||||
order='C')
|
||||
descriptors = np.zeros((keypoints_loc.shape[0], descriptor_size),
|
||||
dtype=bool, order='C')
|
||||
|
||||
# Sampling pairs of decision pixels in patch_size x patch_size window
|
||||
if mode == 'normal':
|
||||
@@ -175,6 +179,6 @@ def descriptor_brief(image, keypoints, descriptor_size=256, mode='normal',
|
||||
pos1 = np.ascontiguousarray(pos1)
|
||||
pos2 = np.ascontiguousarray(pos2)
|
||||
|
||||
_brief_loop(image, descriptors.view(np.uint8), keypoints, pos1, pos2)
|
||||
_brief_loop(image, descriptors.view(np.uint8), keypoints_loc, pos1, pos2)
|
||||
|
||||
return descriptors, keypoints
|
||||
|
||||
@@ -2,7 +2,7 @@ import numpy as np
|
||||
|
||||
from skimage.feature.util import (_mask_border_keypoints,
|
||||
_prepare_grayscale_input_2D,
|
||||
_create_keypoint_recarray)
|
||||
create_keypoint_recarray)
|
||||
|
||||
from skimage.feature import (corner_fast, corner_orientations, corner_peaks,
|
||||
corner_harris)
|
||||
@@ -116,10 +116,10 @@ def keypoints_orb(image, n_keypoints=500, fast_n=9, fast_threshold=0.08,
|
||||
orientations = np.hstack(orientations_list)
|
||||
octaves = downscale ** np.hstack(scales_list)
|
||||
harris_measure = np.hstack(harris_response_list)
|
||||
keypoints = _create_keypoint_recarray(keypoints_array[:, 0],
|
||||
keypoints_array[:, 1],
|
||||
octaves, orientations,
|
||||
harris_measure)
|
||||
keypoints = create_keypoint_recarray(keypoints_array[:, 0],
|
||||
keypoints_array[:, 1],
|
||||
octaves, orientations,
|
||||
harris_measure)
|
||||
|
||||
if keypoints.shape[0] < n_keypoints:
|
||||
return keypoints
|
||||
|
||||
@@ -3,14 +3,17 @@ from numpy.testing import assert_array_equal, assert_raises
|
||||
from skimage import data
|
||||
from skimage import transform as tf
|
||||
from skimage.color import rgb2gray
|
||||
from skimage.feature import (descriptor_brief, match_binary_descriptors, corner_peaks,
|
||||
corner_harris)
|
||||
from skimage.feature import (descriptor_brief, match_binary_descriptors,
|
||||
corner_peaks, corner_harris,
|
||||
create_keypoint_recarray)
|
||||
|
||||
|
||||
def test_descriptor_brief_color_image_unsupported_error():
|
||||
"""Brief descriptors can be evaluated on gray-scale images only."""
|
||||
img = np.zeros((20, 20, 3))
|
||||
keypoints = [[7, 5], [11, 13]]
|
||||
keypoints_loc = np.asarray([[7, 5], [11, 13]])
|
||||
keypoints = create_keypoint_recarray(keypoints_loc[:, 0],
|
||||
keypoints_loc[:, 1])
|
||||
assert_raises(ValueError, descriptor_brief, img, keypoints)
|
||||
|
||||
|
||||
@@ -18,7 +21,10 @@ def test_descriptor_brief_normal_mode():
|
||||
"""Verify the computed BRIEF descriptors with expected for normal mode."""
|
||||
img = data.lena()
|
||||
img = rgb2gray(img)
|
||||
keypoints = corner_peaks(corner_harris(img), min_distance=5)
|
||||
keypoints_loc = corner_peaks(corner_harris(img), min_distance=5)
|
||||
keypoints = create_keypoint_recarray(keypoints_loc[:, 0],
|
||||
keypoints_loc[:, 1])
|
||||
|
||||
descriptors, keypoints = descriptor_brief(img, keypoints[:8],
|
||||
descriptor_size=8)
|
||||
|
||||
@@ -38,7 +44,9 @@ def test_descriptor_brief_uniform_mode():
|
||||
"""Verify the computed BRIEF descriptors with expected for uniform mode."""
|
||||
img = data.lena()
|
||||
img = rgb2gray(img)
|
||||
keypoints = corner_peaks(corner_harris(img), min_distance=5)
|
||||
keypoints_loc = corner_peaks(corner_harris(img), min_distance=5)
|
||||
keypoints = create_keypoint_recarray(keypoints_loc[:, 0],
|
||||
keypoints_loc[:, 1])
|
||||
descriptors, keypoints = descriptor_brief(img, keypoints[:8],
|
||||
descriptor_size=8,
|
||||
mode='uniform')
|
||||
|
||||
@@ -3,7 +3,7 @@ import numpy as np
|
||||
from skimage.util import img_as_float
|
||||
|
||||
|
||||
def _create_keypoint_recarray(row, col, octave=None, orientation=None,
|
||||
def create_keypoint_recarray(row, col, octave=None, orientation=None,
|
||||
response=None):
|
||||
keypoints = np.zeros(row.shape[0],
|
||||
dtype=[('row', np.double), ('col', np.double),
|
||||
|
||||
Reference in New Issue
Block a user