我一直在检查图像中的重复区域。我使用SURF来描述关键点,然后测量欧几里德距离并获得两组可以指示可能重复区域的特征。
我正在尝试修改this代码以将其应用于单个图像,但由于我正在处理单个图像,因此我不需要matchFeatures函数。所以我没有任何indexPairs变量,该变量依赖于该变量。有没有办法获得这个变量?
如果那是不可能的,那么如果我可以在由两个m×n阵列表示的图像上的两组SURF特征之间画一条线就没问题。
(b)和(d)图像here是我想要获得的结果类型。
任何帮助将不胜感激,谢谢。
答案 0 :(得分:1)
您的案例中的整个过程与this相同。如果你有图像中区域的坐标,你只需要裁剪这些区域并将它们用作I2 this(I1是图像中你应首先裁剪它的参考区域)。另一方面,如果您没有区域的坐标,您可以在图像中随机选择x和y坐标,然后在循环中逐步评估它们。例如,如果源图像给出为 input 然后我们可以通过这个找到类似的模板候选人:
%% Step 1: Read Images
clc;clear all;close all;
template_coordinate=[27.5 55.5 269 268];
sample_coordinates=[406.5 48.5 269 268];
templateImage = imcrop(imread('german.png'),template_coordinate);
templateImage=rgb2gray(templateImage);
for i=1:size(sample_coordinates,1)
sampleImage = imcrop(imread('german.png'),sample_coordinates(i,:));
sampleImage=rgb2gray(sampleImage);
%% Step 2: Detect Feature Points
% Detect feature points in both images.
templatePoints = detectSURFFeatures(templateImage);
samplePoints = detectSURFFeatures(sampleImage);
%% Step 3: Extract Feature Descriptors
% Extract feature descriptors at the interest points in both images.
[boxFeatures, templatePoints] = extractFeatures(templateImage, templatePoints);
[sceneFeatures, samplePoints] = extractFeatures(sampleImage, samplePoints);
%% Step 4: Find Putative Point Matches
% Match the features using their descriptors.
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
%% Step 4: Make decision of similarity
% This can be done by counting the number of the size(boxPairs,1) or other metrics
%% Step 5: display pair points
matchedBoxPoints = templatePoints(boxPairs(:, 1), :);
matchedScenePoints = samplePoints(boxPairs(:, 2), :);
figure;imshow(imread('german.png'))
hold on
for n=1:size(matchedBoxPoints.Location,1)
point1=round(matchedBoxPoints.Location(n,:))+template_coordinate(1:2);
point2=round(matchedScenePoints.Location(n,:))+sample_coordinates(1:2);
xy = [point1;point2];
% plot([point1(2),point2(2)],[point1(1),point2(1)],'Color','b','LineWidth',2)
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(point1(1),point1(2),'x','LineWidth',2,'Color','red');
plot(point2(1),point2(2),'x','LineWidth',2,'Color','yellow');
end
end
获取类似output
的输出