Loop through .mat images and compare each

2 views (last 30 days)
Colin
Colin on 24 Jan 2014
I have a two template image with feature points mapped, I then want to map the feature points on a sample image and count how many feature point matches there are on each of the template image.
The problem I'm having is that is comparing the sample image to the first template image twice instead of moving onto the second image.
The code to create my template images:
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectSURFFeatures(I1);
save('im1.mat', 'I1','points1');
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/templateTwo.jpg'));
points1 = detectSURFFeatures(I1);
save('im2.mat', 'I1','points1');
and this is the code I'm using to map the sample image and compare to the two template images:
myFolder = '/home/colin/';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, 'im*.mat');
matFiles = dir(filePattern);
for k = 1:length(matFiles)
matFilename = fullfile(myFolder, matFiles(k).name)
matData = load(matFilename);
for row = length(matFiles)
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectSURFFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
[features1, valid_points1] = extractFeatures(I1, points1);
indexPairs = matchFeatures(features1, features2);
matched_points1 = valid_points1(indexPairs(:, 1), :);
matched_points2 = valid_points2(indexPairs(:, 2), :);
figure; showMatchedFeatures(I1, I2, matched_points1, matched_points2);
totalMatchedPoints = matched_points1.Count;
disp(totalMatchedPoints);
end
end

Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!