Pregunta

I have a image (.fig) saved with feature points plotted using the harris corner detector, I then want to map the feature points on a second image and compare them to the saved image to show the matched feature points. I would like some help on how to go about this.

Code to map "template" image:

I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
imshow(I1); hold on;
plot(points1);

I just saved this image using the "File -> saveas" option when it was plotted.

I am then trying to run a separate script to plot the features on the new image and compare them, this is where I'm having problems.

Compare Script:

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);

As you can imagine I am getting a series of errors:

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);
¿Fue útil?

Solución

You are not saving the correct information. When you save a .fig, you are only saving the plot.

You need to save I1 and points1:

I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
save('im1.mat', 'I1','points1');

Now you can use the info:

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);

Optionally, you can compute the features1 variable in the first step and save it (instead of using I1 and 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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top