mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-11 23:42:45 +08:00
Fixing bugs and making code compatible with Python 3
This commit is contained in:
+22
-18
@@ -55,9 +55,9 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49,
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from skimage.feature.corner import *
|
||||
>>> from skimage.feature import pairwise_hamming_distance
|
||||
>>> from skimage.feature._brief import *
|
||||
>>> import numpy as np
|
||||
>>> from skimage.feature.corner import corner_peaks, corner_harris
|
||||
>>> from skimage.feature import pairwise_hamming_distance, brief, match_keypoints_brief
|
||||
>>> square1 = np.zeros([8, 8], dtype=np.int32)
|
||||
>>> square1[2:6, 2:6] = 1
|
||||
>>> square1
|
||||
@@ -111,15 +111,17 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49,
|
||||
[ 0.375 , 0.6328125, 0.0390625, 0.328125 ],
|
||||
[ 0.625 , 0.3671875, 0.34375 , 0.0234375]])
|
||||
>>> match_keypoints_brief(keypoints1, descriptors1, keypoints2, descriptors2)
|
||||
array([[[2, 2],
|
||||
[2, 5],
|
||||
[5, 2],
|
||||
[5, 5]],
|
||||
array([[[ 2., 2.],
|
||||
[ 2., 2.]],
|
||||
|
||||
[[2, 2],
|
||||
[2, 6],
|
||||
[6, 2],
|
||||
[6, 6]]])
|
||||
[[ 2., 5.],
|
||||
[ 2., 6.]],
|
||||
|
||||
[[ 5., 2.],
|
||||
[ 6., 2.]],
|
||||
|
||||
[[ 5., 5.],
|
||||
[ 6., 6.]]])
|
||||
|
||||
"""
|
||||
np.random.seed(sample_seed)
|
||||
@@ -140,7 +142,7 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49,
|
||||
|
||||
# Removing keypoints that are within (patch_size / 2) distance from the
|
||||
# image border
|
||||
keypoints = _remove_border_keypoints(image, keypoints, patch_size / 2)
|
||||
keypoints = _remove_border_keypoints(image, keypoints, patch_size // 2)
|
||||
keypoints = np.ascontiguousarray(keypoints)
|
||||
|
||||
descriptors = np.zeros((keypoints.shape[0], descriptor_size), dtype=bool,
|
||||
@@ -149,10 +151,10 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49,
|
||||
# Sampling pairs of decision pixels in patch_size x patch_size window
|
||||
if mode == 'normal':
|
||||
|
||||
samples = (patch_size / 5) * np.random.randn(descriptor_size * 8)
|
||||
samples = (patch_size / 5.0) * np.random.randn(descriptor_size * 8)
|
||||
samples = np.array(samples, dtype=np.int32)
|
||||
samples = samples[(samples < (patch_size / 2))
|
||||
& (samples > - (patch_size - 1) / 2)]
|
||||
samples = samples[(samples < (patch_size // 2))
|
||||
& (samples > - (patch_size - 2) // 2)]
|
||||
|
||||
pos1 = samples[:descriptor_size * 2]
|
||||
pos1 = pos1.reshape(descriptor_size, 2)
|
||||
@@ -161,7 +163,7 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49,
|
||||
|
||||
else:
|
||||
|
||||
samples = np.random.randint(-patch_size / 2, (patch_size / 2) + 1,
|
||||
samples = np.random.randint(-(patch_size - 2) // 2, (patch_size // 2) + 1,
|
||||
(descriptor_size * 2, 2))
|
||||
pos1, pos2 = np.split(samples, 2)
|
||||
|
||||
@@ -194,7 +196,7 @@ def match_keypoints_brief(keypoints1, descriptors1, keypoints2,
|
||||
|
||||
Returns
|
||||
-------
|
||||
match_keypoints_brief : (2, Q, 2) ndarray
|
||||
match_keypoints_brief : (Q, 2, 2) ndarray
|
||||
Location of Q matched keypoint pairs from two images.
|
||||
|
||||
"""
|
||||
@@ -214,6 +216,8 @@ def match_keypoints_brief(keypoints1, descriptors1, keypoints2,
|
||||
temp = distance > threshold
|
||||
row_check = ~ np.all(temp, axis = 1)
|
||||
matched_keypoints2 = keypoints2[np.argmin(distance, axis=1)]
|
||||
matched_keypoint_pairs = np.array([keypoints1[row_check], matched_keypoints2[row_check]])
|
||||
matched_keypoint_pairs = np.zeros((np.sum(row_check), 2, 2))
|
||||
matched_keypoint_pairs[:, 0, :] = keypoints1[row_check]
|
||||
matched_keypoint_pairs[:, 1, :] = matched_keypoints2[row_check]
|
||||
|
||||
return matched_keypoint_pairs
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_match_keypoints_brief_lena_translation():
|
||||
keypoints2, descriptors2,
|
||||
threshold=0.10)
|
||||
|
||||
assert_array_equal(matched_keypoints[0,::], matched_keypoints[1,::] +
|
||||
assert_array_equal(matched_keypoints[:, 0,:], matched_keypoints[:, 1,:] +
|
||||
[20, 15])
|
||||
|
||||
|
||||
@@ -56,15 +56,22 @@ def test_match_keypoints_brief_lena_rotation():
|
||||
matched_keypoints = match_keypoints_brief(keypoints1, descriptors1,
|
||||
keypoints2, descriptors2,
|
||||
threshold=0.07)
|
||||
expected = np.array([[[248, 147],
|
||||
[263, 272],
|
||||
[271, 120],
|
||||
[414, 70],
|
||||
[454, 176]],
|
||||
expected = np.array([[[ 263., 272.],
|
||||
[ 234., 298.]],
|
||||
|
||||
[[ 271., 120.],
|
||||
[ 258., 146.]],
|
||||
|
||||
[[ 323., 164.],
|
||||
[ 305., 195.]],
|
||||
|
||||
[[ 414., 70.],
|
||||
[ 405., 111.]],
|
||||
|
||||
[[ 435., 181.],
|
||||
[ 415., 223.]],
|
||||
|
||||
[[ 454., 176.],
|
||||
[ 435., 221.]]])
|
||||
|
||||
[[232, 171],
|
||||
[234, 298],
|
||||
[258, 146],
|
||||
[405, 111],
|
||||
[435, 221]]])
|
||||
assert_array_equal(matched_keypoints, expected)
|
||||
|
||||
Reference in New Issue
Block a user