代码语言:javascript复制
from skimage.io import imread
from skimage.color import rgb2gray
from matplotlib import pylab as pylab
from skimage import transform as transform
from skimage.feature import match_descriptors, corner_peaks,corner_harris, plot_matches, BRIEF
img1=rgb2gray(imread('C:/Users/xpp/Desktop/Lena.png'))#将彩色图片转换为灰度图片
affine_trans=transform.AffineTransform(scale=(1.2,1.2),translation=(0,-100))#图像仿射
img2=transform.warp(img1,affine_trans)
img3=transform.rotate(img1,25)#图像旋转
coords1,coords2,coords3=corner_harris(img1),corner_harris(img2),corner_harris(img3)#Harris角点检测
coords1[coords1>0.01*coords1.max()]=1#阈值
coords2[coords2>0.01*coords2.max()]=1#阈值
coords3[coords3>0.01*coords3.max()]=1#阈值
keypoints1=corner_peaks(coords1,min_distance=5)#计算Harris角点
keypoints2=corner_peaks(coords2,min_distance=5)#计算Harris角点
keypoints3=corner_peaks(coords3,min_distance=5)#计算Harris角点
extractor=BRIEF()
extractor.extract(img1,keypoints1)
keypoints1,descriptors1=keypoints1[extractor.mask],extractor.descriptors#特征点检测
extractor.extract(img2,keypoints2)
keypoints2,descriptors2=keypoints2[extractor.mask],extractor.descriptors#特征点检测
extractor.extract(img3,keypoints3)
keypoints3,descriptors3=keypoints3[extractor.mask],extractor.descriptors#特征点检测
matches12=match_descriptors(descriptors1,descriptors2,cross_check=True)#图像匹配
matches13=match_descriptors(descriptors1,descriptors3,cross_check=True)#图像匹配
fig,axes=pylab.subplots(nrows=2,ncols=1,figsize=(20,20))
pylab.gray()
plot_matches(axes[0],img1,img2,keypoints1,keypoints2,matches12)
axes[0].axis('off')
axes[0].set_title("Original Image vs. Transformed Image")
plot_matches(axes[1],img1,img3,keypoints1,keypoints3,matches13)
axes[1].axis('off')
axes[1].set_title("Original Image vs. Transformed Image"),
pylab.show()
算法:BRIEF关键点匹配是短二进制特征描述符进行关键点匹配,使用一组强度差测试来进行计算,利用该描述符使用汉明距离度量进行匹配是非常有效。BRIEF虽然不提供旋转不变性,但可以通过检测不同尺度的特征来获得尺度不变性。