我有一个图像(.fig)保存了使用哈里斯角点检测器绘制的特征点,然后我想要在第二个图像上映射特征点并将它们与保存的图像进行比较以显示匹配的特征点。我想帮助解决这个问题。
映射“模板”图片的代码:
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
imshow(I1); hold on;
plot(points1);
我刚刚绘制时使用“文件 - > saveas”选项保存了此图像。
然后我尝试运行一个单独的脚本来绘制新图像上的特征并进行比较,这就是我遇到问题的地方。
比较脚本:
I1 = hgload('/home/colin/tmp/untitled.fig');
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectHarrisFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
indexPairs = matchFeatures(I1, features2);
matched_points2 = valid_points2(indexPairs(:, 2), :);
figure; showMatchedFeatures(I1, I2, matched_points2);
您可以想象我遇到了一系列错误:
Error using coder.internal.errorIf (line 9)
Expected FEATURES1 and FEATURES2 to be the same class.
Error in matchFeatures>assignFeaturesAndMetric (line 356)
coder.internal.errorIf(~isequal(class(f1), class(f2)),...
Error in matchFeatures>parseInputs (line 343)
[features1, features2, metric] = assignFeaturesAndMetric(f1, f2, metric);
Error in matchFeatures (line 196)
[features1, features2, metric, match_thresh, method, maxRatioThreshold, ...
Error in comparePoints (line 6)
indexPairs = matchFeatures(I1, features2);
答案 0 :(得分:2)
您没有保存正确的信息。保存 .fig 时,只保存图。
您需要保存I1
和points1
:
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
save('im1.mat', 'I1','points1');
现在您可以使用信息:
load('im1.mat');%This loads I1 and points1
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectHarrisFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
[features1, valid_points1] = extractFeatures(I1, points1);
indexPairs = matchFeatures(features1, features2);
(可选),您可以在第一步中计算features1
变量并保存(而不是使用I1
和points1
):
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
[features1, valid_points1] = extractFeatures(I1, points1);
save('im1.mat', 'features1');
load('im1.mat');%This loads features1
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectHarrisFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
indexPairs = matchFeatures(features1, features2);