首页 > 编程语言 >基于SIFT特征提取的图像拼接算法matlab仿真

基于SIFT特征提取的图像拼接算法matlab仿真

时间:2022-10-20 13:35:03浏览次数:74  
标签:des1 img3 SIFT matchTable matlab 图像 特征提取 size

目录

一、理论基础

二、核心MATLAB程序

三、MATLAB仿真测试结果

一、理论基础

SIFT算法得到了图像中的特征点以及相应的特征描述,如何把两张图像中的特征点匹配起来呢?一般的可以使用K近邻(KNN)算法。K近邻算法求取在空间中距离最近的K个数据点,并将这些数据点归为一类。在进行特征点匹配时,一般使用KNN算法找到最近邻的两个数据点,如果最接近和次接近的比值大于一个既定的值,那么我们保留这个最接近的值,认为它和其匹配的点为good match(有Lowe在SIFT论文中提出)。

SIFT(Scale invariant feature transform),即尺度不变特征变换描述子,其可以从图像中提取稳定的特征数据,其对图像的旋转、阴影干扰、噪声干扰、移动以及空间扭曲等影响有着较好的不变性。基于SIFT的图像特征提取原理如下:

步骤一、图像转换到尺度空间。图像的尺度空间表示方式通常情况下是将图像和高斯核函数进行卷积计算,其计算公式如下:

 

 

 

 

 

 

二、核心MATLAB程序



function [matchLoc1,matchLoc2] = func_siftMatch(img1, img2)


[des1,loc1] = sift(img1);
[des2,loc2] = sift(img2);

distRatio = 0.8;

% For each descriptor in the first image, select its match to second image.
des2t = des2'; % Precompute matrix transpose
matchTable = zeros(1,size(des1,1));
for i = 1 : size(des1,1)
dotprods = des1(i,:) * des2t; % Computes vector of dot products
[vals,indx] = sort(acos(dotprods)); % Take inverse cosine and sort results

% Check if nearest neighbor has angle less than distRatio times 2nd.
if (vals(1) < distRatio * vals(2))
matchTable(i) = indx(1);
else
matchTable(i) = 0;
end
end

img3 = func_appendimages(img1,img2);

% Show a figure with lines joining the accepted matches.
figure('Position', [100 100 size(img3,2) size(img3,1)]);
subplot(211);
colormap('gray');
imagesc(img3);
subplot(212);
colormap('gray');
imagesc(img3);
hold on;
cols1 = size(img1,2);
for i = 1: size(des1,1)
if (matchTable(i) > 0)
line([loc1(i,2) loc2(matchTable(i),2)+cols1], ...
[loc1(i,1) loc2(matchTable(i),1)], 'Color', 'g');
end
end
title('SIFT匹配效果');
hold off;
num = sum(matchTable > 0);
fprintf('Found %d matches.\n', num);

idx1 = find(matchTable);
idx2 = matchTable(idx1);
x1 = loc1(idx1,2);
x2 = loc2(idx2,2);
y1 = loc1(idx1,1);
y2 = loc2(idx2,1);

matchLoc1 = [x1,y1];
matchLoc2 = [x2,y2];

end

三、MATLAB仿真测试结果

 

 

 

 

  A09-54

 

标签:des1,img3,SIFT,matchTable,matlab,图像,特征提取,size
From: https://www.cnblogs.com/matlabfpga/p/16809546.html

相关文章