BRIEF 二元描述子#

此範例示範 BRIEF 二元描述演算法。描述子由相對較少的位元組成,可以使用一組強度差異測試來計算。短二元描述子導致低記憶體佔用空間,並基於漢明距離度量實現非常有效的匹配。BRIEF 不提供旋轉不變性。透過在不同的尺度上偵測和提取特徵,可以實現尺度不變性。

Original Image vs. Transformed Image, Original Image vs. Transformed Image
from skimage import data
from skimage import transform
from skimage.feature import (
    match_descriptors,
    corner_peaks,
    corner_harris,
    plot_matched_features,
    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_matched_features(
    img1,
    img2,
    keypoints0=keypoints1,
    keypoints1=keypoints2,
    matches=matches12,
    ax=ax[0],
)
ax[0].axis('off')
ax[0].set_title("Original Image vs. Transformed Image")

plot_matched_features(
    img1,
    img3,
    keypoints0=keypoints1,
    keypoints1=keypoints3,
    matches=matches13,
    ax=ax[1],
)
ax[1].axis('off')
ax[1].set_title("Original Image vs. Transformed Image")


plt.show()

指令碼的總執行時間: (0 分鐘 0.590 秒)

由 Sphinx-Gallery 產生的圖庫