如何使用MATLAB在多个图像中找到精确的SURF匹配点?

时间:2016-03-29 05:13:05

标签: matlab feature-extraction surf

我有来自3个不同位置的3个相同区域的图像,并且在所有图像上都有SURF特征/点,现在我想提取所有图像中常见的点,我在Matlab中尝试了一些编码,但问题是它的问题在1张图片中给出了异常值,但在其他2张图片中则不是。

function [TotalMachedPt,Pairs,R,b] = DetectSURFFeatures(  )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
I1 = rgb2gray(imread('IMG_201.JPG'));
I2 = rgb2gray(imread('IMG_202.JPG'));
I3 = rgb2gray(imread('IMG_203.JPG'));

% Detect SURF features
Points1 = detectSURFFeatures(I1,'MetricThreshold',1000);
Points2 = detectSURFFeatures(I2,'MetricThreshold',1000);
Points3 = detectSURFFeatures(I3,'MetricThreshold',1000);

% Extract the neighborhood features
[features1, valid_points1] = extractFeatures(I1, Points1);
[features2, valid_points2] = extractFeatures(I2, Points2);
[features3, valid_points3] = extractFeatures(I3, Points3);

% Match the features
indexPairs1 = matchFeatures(features1, features2, 'Prenormalized', true);
indexPairs2 = matchFeatures(features2, features3, 'Prenormalized', true);

% Retrieve the locations of the corresponding points for each image
matched_pts1 = valid_points1(indexPairs1(:, 1));
matched_pts2 = valid_points2(indexPairs1(:, 2));
matched_pts3 = valid_points2(indexPairs2(:, 1));
matched_pts4 = valid_points3(indexPairs2(:, 2));

% Remove Outlies
[F1, inliers1] = estimateFundamentalMatrix(matched_pts1,matched_pts2, 'NumTrials', 2000);
[F2, inliers2] = estimateFundamentalMatrix(matched_pts3,matched_pts4, 'NumTrials', 2000);

% Removal of unwanted values from 1st & 2nd pairs
Temp1 = indexPairs1;
Temp1(~inliers1,:) = [];

Temp2 = indexPairs2;
Temp2(~inliers2,:) = [];

% Extracting cleaned matched pts 
newmatched_pts1 = valid_points1(Temp1(:, 1));
newmatched_pts2 = valid_points2(Temp1(:, 2));
newmatched_pts3 = valid_points2(Temp2(:, 1));
newmatched_pts4 = valid_points3(Temp2(:, 2));

% Getting locations of matched pts
a11 = (newmatched_pts1.Location);
b11 = (newmatched_pts2.Location);
c11 = (newmatched_pts3.Location);
d11 = (newmatched_pts4.Location);

% Finding the common location values in all images
z = 0;
z = 0;
for i = 1:length(c11)
    x = c11(i,1);
    y = c11(i,2);
    for j = 1:length(b11)
        if (x == b11(j,1) && y == b11(j,2))
            z = z + 1;
            Pairs(z,[1:2 4:5 7:8 10:11]) = [a11(j,:) b11(j,:) c11(i,:) d11(i,:)]; 
        end
    end
end

figure, imshow(I1), hold on, plot(Pairs(:,1),Pairs(:,2), 'ro');
figure, imshow(I2), hold on, plot(Pairs(:,3),Pairs(:,4), 'bo');
figure, imshow(I3), hold on, plot(Pairs(:,5),Pairs(:,6), 'go');

end

0 个答案:

没有答案