基于ORB算法的图像匹配

基础理论

2006RostenDrummond提出一种使用决策树学习方法加速的角点检测算法,即FAST算法,该算法认为若某点像素值与其周围某邻域内一定数量的点的像素值相差较大,则该像素可能是角点。

其计算步骤如下:

1)基于FAST算法进行特征点的提取

2)特征点附加方向

Matlab程序

ORB算法的Matlab主程序代码实现如下:
%% 主程序
% 读取图像
im1 = imread('baby1.JPG');
im2 = imread('baby2.JPG');
scale = [1, 0.75, 0.5, 0.25];
im1_grey = rgb2gray(im1);
im2_grey = rgb2gray(im2);
% FAST算法进行特征点的提取及得分计算
[corner1, fscore1] = fast9(im1_grey,20, 1);
[corner2, fscore2] = fast9(im2_grey,20, 1);
% 非极大值抑制
[corner1,fscore1] = FAST_filter(im1_grey,corner1,fscore1);
[corner2,fscore2] = FAST_filter(im2_grey,corner2,fscore2);
% 提取 Harris 特征点及得分
H1 = harris(im1_grey);
H2 = harris(im2_grey);
harris1 = H1(sub2ind(size(H1),corner1(:,2),corner1(:,1)));
harris2 = H2(sub2ind(size(H1),corner2(:,2),corner2(:,1)));
% 利用Harris得分优化 FAST 特征点
[~,idx1] = sort(harris1);
[~,idx2] = sort(harris2);
cnr1 = corner1(idx1(1:400),:);
cnr2 = corner2(idx2(1:400),:);
% 特征点附加方向提取
angle1 = orientation(im1_grey,[cnr1(:,2),cnr1(:,1)]);
angle2 = orientation(im2_grey,[cnr2(:,2),cnr2(:,1)]);
% 计算BRIEF附加旋转
run('sampling_param.m')
br1 = rBRIEF(im1_grey,cnr1,sample,angle1);
br2 = rBRIEF(im2_grey,cnr2,sample,angle2);
% 寻找匹配点 
matches = findmatches(br1,br2, cnr1, cnr2);
% 匹配点(注意,存在大量异常值!)
feature1 = matches(:,1:2);
feature2 = matches(:,3:4);
%随机样本一致性(RANdom SAmple Consensus,RANSAC)
%去除异常值是必要的一步!
[H,inlr] = computeHomography(feature1,feature2,3,1000);
% 转置、画图;
Hp = H';
tform = projective2d(Hp);
I = imwarp(im1,tform,'OutputView', imref2d(size(im2)));
I = uint8((double(I) + double(im2))./2);
%% 匹配结果显示
newImg = cat(2,im2_grey,im1_grey); %两张图像并排显示
figure;imshow(newImg)
% imwrite(newImg,'match2.jpg');
hold on
plot(feature2(:,1),feature2(:,2), 'ro','MarkerSize',5,'LineWidth',0.7)
plot(feature1(:,1)+size(im2,2),feature1(:,2), 'm*','MarkerSize',5,'LineWidth',0.7)
for i = 1:size(matches,1)
    plot([matches(i,3) matches(i,1)+size(im2,2)],[matches(i,4) matches(i,2)],'c')
end
% title('ORB图像匹配结果')
frame=getframe(gcf);
im=frame2im(frame);
imwrite(im,'ORB图像匹配结果.jpg');

案例图片

基于ORB算法的图像匹配_第1张图片

基于ORB算法的图像匹配结果 

你可能感兴趣的:(Matlab,机器视觉,算法,计算机视觉,图像处理)