登录VLFEAT官网(https://www.vlfeat.org)下载VLFEAT工具包(https://www.vlfeat.org/download/vlfeat-0.9.21-bin.tar.gz)。
解压下载好的工具包:
在解压路径下建立.m文件,并测试工具包能否使用:
run('...\vlfeat-0.9.21-bin\vlfeat-0.9.21\toolbox\vl_setup.m') vl_version verbose
加载成功显示,命令行窗口显示如下信息:
载入一张图片试试看:
I = vl_impattern('river1');
image(I);
显示效果如下:
这里要注意vl_impattern()这个函数只能载入存放在vlfeat中的测试图片:
如果要使用本地图片,则调用imread():
Image1=imread('Test1.jpg'); Image2=imread('Test2.jpg');
对载入的图片进行灰度化:
IMG1 = single(rgb2gray(Image1)); IMG2 = single(rgb2gray(Image2));
然后提取SIFT特征点:
[f1, d1] = vl_sift(IMG1,'Levels',3,'PeakThresh', 5); [f2, d2] = vl_sift(IMG2,'Levels',3,'PeakThresh', 5);
对特征点进行匹配:
[matches, scores] = vl_ubcmatch(d1, d2); [dump,scoreind]=sort(scores,'ascend');
输出匹配后效果
figure; image(newfig); axis image f2Moved=f2; f2Moved(1,:) = f2Moved(1,:)+size(IMG1,2); h1 = vl_plotframe(f1); h2 = vl_plotframe(f2Moved); set(h1,'color','g','linewidth',2) ; set(h2,'color','r','linewidth',2); hold on plotRatio=0.1; for i= 1:fix(plotRatio*size(matches,2)) idx = scoreind(i); line([f1(1,matches(1,idx)) f2Moved(1,matches(2,idx))],... [f1(2,matches(1,idx)) f2Moved(2,matches(2,idx))], 'linewidth',1, 'color','b') end hold off
输出效果如图所示: