本文主要是介绍如何使用VL_feat入门SIFT,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先下载vl_feat包http://www.vlfeat.org/download.html
正常解压就完事了
然后在程序开头输入加载vl_feat
run('.\vlfeat-0.9.21-bin\vlfeat-0.9.21\toolbox\vl_setup.m');
% 测试vlfeat是否成功
vl_version verbose
然后开始代码测试两张图像使用sift匹配显示
二、加载图片
% 图片1
img1ori = imread('JapanCrane.jpg');
img1 = single(rgb2gray(img1ori));
% 图片2
img2ori = imread('Snowball.jpg');
% img2ori = imread('Crane.jpg');
img2 = single(rgb2gray(img2ori));三、提取SIFT特征,匹配特征点
[f1,d1] = vl_sift(img1,'Levels',3,'PeakThresh',1);
[f2,d2] = vl_sift(img2,'Levels',3,'PeakThresh',1);
[matches,scores] = vl_ubcmatch(d1,d2);
[dump,scoreind] = sort(scores,'ascend');三、绘制组合图片
% 创建一个(1080*2030*3)的数组
newfig=zeros(size(img1,1), size(img1,2)+size(img2,2),3);
newfig(:,1:size(img1,2),:) = img1ori;
newfig(1:size(img2,1) ,(size(img1,2)+1):end,:)=img2ori;
% uint8将single或者double类型的数组转换成8位无符号整型数组
newfig=uint8(newfig);
figure;
image(newfig);
% 显示坐标轴
axis image;
% colormap(gray);四、绘制匹配特征点
figure;
image(newfig);
axis image;
f2Moved = f2;
f2Moved(1,:) = f2Moved(1,:)+size(img1,2);
% plotframe返回图像句柄
h1 = vl_plotframe(f1);
h2 = vl_plotframe(f2Moved);
% set设置图形对象属性
set(h1,'color','g','linewidth',2);
set(h2,'color','r','linewidth',2);
hold on
% 绘制scores前5%
plotRatio=0.05;
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','r')
end
hold off
大功告成!!!
这篇关于如何使用VL_feat入门SIFT的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!