SIFT 特征检测器和描述子提取器#

此示例演示了SIFT特征检测及其描述算法。

尺度不变特征变换(SIFT)[1]_ 于1999年发表,至今仍是可用的最受欢迎的特征检测器之一,因为它承诺“对图像缩放、平移和旋转不变,对光照变化和仿射或3D投影部分不变”[2]。其最大的缺点是运行时间,据说比ORB慢“两个数量级”[3],这使得它不适合实时应用。

参考文献#

Original Image vs. Flipped Image (all keypoints and matches), Original Image vs. Flipped Image (subset of matches for visibility), Original Image vs. Transformed Image (all keypoints and matches), Original Image vs. Transformed Image (subset of matches for visibility)
/Users/cw/baidu/code/fin_tool/github/scikit-image/doc/examples/features_detection/plot_sift.py:67: 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_sift.py:71: 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_sift.py:77: 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_sift.py:85: FutureWarning:

`plot_matches` is deprecated since version 0.23 and will be removed in version 0.25. Use `skimage.feature.plot_matched_features` instead.

import matplotlib.pyplot as plt

from skimage import data
from skimage import transform
from skimage.color import rgb2gray
from skimage.feature import match_descriptors, plot_matches, SIFT

img1 = rgb2gray(data.astronaut())
img2 = transform.rotate(img1, 180)
tform = transform.AffineTransform(scale=(1.3, 1.1), rotation=0.5, translation=(0, -200))
img3 = transform.warp(img1, tform)

descriptor_extractor = SIFT()

descriptor_extractor.detect_and_extract(img1)
keypoints1 = descriptor_extractor.keypoints
descriptors1 = descriptor_extractor.descriptors

descriptor_extractor.detect_and_extract(img2)
keypoints2 = descriptor_extractor.keypoints
descriptors2 = descriptor_extractor.descriptors

descriptor_extractor.detect_and_extract(img3)
keypoints3 = descriptor_extractor.keypoints
descriptors3 = descriptor_extractor.descriptors

matches12 = match_descriptors(
    descriptors1, descriptors2, max_ratio=0.6, cross_check=True
)
matches13 = match_descriptors(
    descriptors1, descriptors3, max_ratio=0.6, cross_check=True
)
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(11, 8))

plt.gray()

plot_matches(ax[0, 0], img1, img2, keypoints1, keypoints2, matches12)
ax[0, 0].axis('off')
ax[0, 0].set_title("Original Image vs. Flipped Image\n" "(all keypoints and matches)")

plot_matches(ax[1, 0], img1, img3, keypoints1, keypoints3, matches13)
ax[1, 0].axis('off')
ax[1, 0].set_title(
    "Original Image vs. Transformed Image\n" "(all keypoints and matches)"
)

plot_matches(
    ax[0, 1], img1, img2, keypoints1, keypoints2, matches12[::15], only_matches=True
)
ax[0, 1].axis('off')
ax[0, 1].set_title(
    "Original Image vs. Flipped Image\n" "(subset of matches for visibility)"
)

plot_matches(
    ax[1, 1], img1, img3, keypoints1, keypoints3, matches13[::15], only_matches=True
)
ax[1, 1].axis('off')
ax[1, 1].set_title(
    "Original Image vs. Transformed Image\n" "(subset of matches for visibility)"
)

plt.tight_layout()
plt.show()

脚本总运行时间: (0 分钟 2.198 秒)

由 Sphinx-Gallery 生成的图库