I am trying to extract the SURF points in order to do pattern matching between an input image and a training set of images. I have modified the MATLAB's HOG detection code. However, I am getting an error because the SURF Features for the different images are of different sizes. This was addressed in the HOG detector by CellSize but there is no such parameter for SURF Points.
Is there a way to ensure that the SURF Features from all images are of the same size ?
The error : Subscripted assignment dimension mismatch. Error in SURF2 features(i, :) = extractFeatures(img,points);
%1. Load Image Sets
imgSets = [ imageSet(fullfile('Patterns', 'Cat1')), ...
imageSet(fullfile('Patterns', 'Cat2')), ...
imageSet(fullfile('Patterns', 'Cat3'))...
imageSet(fullfile('Patterns', 'Cat4'))];
{imgSets.Description } % display all labels on one line
[imgSets.Count] % show the corresponding count of images
%2. Prepare Training and Validation Image Sets
%2.1 Balance number of each training set
% determine the smallest amount of images in a category
minSetCount = min([imgSets.Count]);
% Use partition method to trim the set.
imgSets = partition(imgSets, minSetCount, 'randomize');
% Notice that each set now has exactly the same number of images.
[imgSets.Count]
%2.2 Separate sets into training and validation data. 30% of the images
%for training data and the remainder 70% for validation data
[trainingSets, validationSets] = partition(imgSets, 0.3, 'randomize');
img = read(trainingSets(3), 4);
img = rgb2gray(img);
%3. Detect SURF Points
points =detectSURFFeatures(img);
points = points.selectStrongest(15);
[feats,vPoints] = extractFeatures(img,points);
SURFFeatureSize = length(feats);
trainingFeatures = [];
trainingLabels = [];
for digit = 1:numel(trainingSets)
numImages1 = trainingSets(digit).Count;
features = zeros(numImages1,SURFFeatureSize,'single');
for i = 1:numImages1
img = read(trainingSets(digit), i);
img = rgb2gray(img);
points = detectSURFFeatures(img);
features(i, :) = extractFeatures(img,points);
end
if digit== 1 %plaid = 5
label = [trainingSets(digit).Description,blanks(6)];
end
if digit== 2 %patternless = 11
label = [trainingSets(digit).Description];
end
if digit== 3 %striped = 7
label = [trainingSets(digit).Description,blanks(4)];
end
if digit== 4 %irregular = 9
label = [trainingSets(digit).Description,blanks(2)];
end
% Use the imageSet Description as the training labels. .
labels = repmat(label, numImages1, 1);
trainingFeatures = [trainingFeatures; features]; %#ok<AGROW>
trainingLabels = [trainingLabels; labels ]; %#ok<AGROW>
end
Thank you.
You cannot use SURF directly the same way you use HOG. extractHOGFeatures
computes a single histogram describing the entire image, while extractSURFFeatures
takes a set of points, and computes a descriptor around each point, so it returns multiple vectors. extractHOGFeatures
can also compute point descriptors, but extractSURFFeatures
cannot compute a global image descriptor.
If you want to use SURF for image classficiation, such as digit recognition, You would need to convert a set of SURF descriptors into a single vector. One way to do this is to use the bag-of-features approach.