备注
转到结尾 下载完整的示例代码。或者通过 Binder 在浏览器中运行此示例。
BRIEF 二进制描述符#
这个例子展示了 BRIEF 二进制描述算法。该描述符由相对较少的位组成,并且可以使用一组强度差异测试来计算。短的二进制描述符导致较低的内存占用,并且基于汉明距离度量的匹配非常高效。BRIEF 不提供旋转不变性。通过在不同尺度上检测和提取特征,可以实现尺度不变性。
/Users/cw/baidu/code/fin_tool/github/scikit-image/doc/examples/features_detection/plot_brief.py:58: FutureWarning:
`plot_matches` is deprecated since version 0.23 and will be removed in version 0.25. Use `skimage.feature.plot_matched_features` instead.
/Users/cw/baidu/code/fin_tool/github/scikit-image/doc/examples/features_detection/plot_brief.py:62: FutureWarning:
`plot_matches` is deprecated since version 0.23 and will be removed in version 0.25. Use `skimage.feature.plot_matched_features` instead.
from skimage import data
from skimage import transform
from skimage.feature import (
match_descriptors,
corner_peaks,
corner_harris,
plot_matches,
BRIEF,
)
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
img1 = rgb2gray(data.astronaut())
tform = transform.AffineTransform(scale=(1.2, 1.2), translation=(0, -100))
img2 = transform.warp(img1, tform)
img3 = transform.rotate(img1, 25)
keypoints1 = corner_peaks(corner_harris(img1), min_distance=5, threshold_rel=0.1)
keypoints2 = corner_peaks(corner_harris(img2), min_distance=5, threshold_rel=0.1)
keypoints3 = corner_peaks(corner_harris(img3), min_distance=5, threshold_rel=0.1)
extractor = BRIEF()
extractor.extract(img1, keypoints1)
keypoints1 = keypoints1[extractor.mask]
descriptors1 = extractor.descriptors
extractor.extract(img2, keypoints2)
keypoints2 = keypoints2[extractor.mask]
descriptors2 = extractor.descriptors
extractor.extract(img3, keypoints3)
keypoints3 = keypoints3[extractor.mask]
descriptors3 = extractor.descriptors
matches12 = match_descriptors(descriptors1, descriptors2, cross_check=True)
matches13 = match_descriptors(descriptors1, descriptors3, cross_check=True)
fig, ax = plt.subplots(nrows=2, ncols=1)
plt.gray()
plot_matches(ax[0], img1, img2, keypoints1, keypoints2, matches12)
ax[0].axis('off')
ax[0].set_title("Original Image vs. Transformed Image")
plot_matches(ax[1], img1, img3, keypoints1, keypoints3, matches13)
ax[1].axis('off')
ax[1].set_title("Original Image vs. Transformed Image")
plt.show()
脚本总运行时间: (0 分钟 0.186 秒)