天天看點

SURF特征提取(MSAC算法剔除誤比對)

clc;
clear;
close all;

load colorImage201;
load colorImage202;

% extractFeatures 函數輸入為灰階圖像,是以要将RGB圖像用函數 rgb2gray 進行轉換
image1= rgb2gray(colorImage201);
image2= rgb2gray(colorImage202);

% Surf 特征檢測
ptsImage1 = detectSURFFeatures(image1);
ptsImage2 = detectSURFFeatures(image2);

% Surf 特征提取
[featuresOriginal,validptsImage1] = extractFeatures(image1,ptsImage1);
[featuresDistorted,validptsImage2] = extractFeatures(image2,ptsImage2);

% Surf 特征比對
index_pairs = matchFeatures(featuresOriginal,featuresDistorted);

matchedptsImage1 = validptsImage1(index_pairs(:,1));
matchedptsImage2 = validptsImage2(index_pairs(:,2));

% 顯示有誤比對的情況
figure;
subplot(1,2,1)
showMatchedFeatures(image1,image2,matchedptsImage1,matchedptsImage2);
str=sprintf('Matched inlier points\n(including outliers)');
title(str,'fontname','Times New Roman','FontSize',12);

% estimateGeometricTransform 函數 剔除誤比對 (MSAC算法)
[tform,inlierptsImage2,inlierptsImage1] =estimateGeometricTransform(matchedptsImage2,matchedptsImage1,'similarity');


% 顯示沒有誤比對的情況
subplot(1,2,2)
showMatchedFeatures(image1,image2,inlierptsImage1,inlierptsImage2);
str=sprintf('Matched inlier points\n(excluding outliers)');
title(str,'fontname','Times New Roman','FontSize',12);
           

繼續閱讀