指定提取的 SURF 点的大小

Specify Size of SURF Points Extracted

我正在尝试提取 SURF 点,以便在输入图像和训练图像集之间进行模式匹配。我修改了MATLAB的HOG检测代码。但是,我收到一个错误,因为不同图像的 SURF 特征大小不同。 CellSize 在 HOG 检测器中解决了这个问题,但是 SURF 点没有这样的参数。

有没有办法确保所有图像的 SURF 特征大小相同?

错误: 下标分配尺寸不匹配。 SURF2 错误 功能(我,:) = extractFeatures(img,点);

%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

谢谢。

根据@rayryeng 提供的评论,我已将检测到的特征数组填充到一组预期的数组大小,如下所示:

img = read(trainingSets(3), 4);
img = rgb2gray(img);
%3.   Detect SURF Points
points =detectSURFFeatures(img);
points = points.selectStrongest(15);
[feats,vPoints] = extractFeatures(img,points);
currentSize = size(feats);
rowSize = currentSize (:,1);
expectedRowSize = 15;
differenceRowSize = abs(expectedRowSize- rowSize);

if rowSize ~= expectedRowSize
    z =zeros(differenceRowSize,64,'single');
    feats= vertcat(feats,z);
end

还有其他填充数组的方法(例如使用 padarray),但我更熟悉这种方法。

请随时提供任何替代方法以造福他人。

您不能像使用 HOG 一样直接使用 SURF。 extractHOGFeatures 计算描述整个图像的单个直方图,而 extractSURFFeatures 获取一组点,并计算每个点周围的描述符,因此它 returns 多个向量。 extractHOGFeatures 也可以计算点描述符,但是 extractSURFFeatures 不能计算全局图像描述符。

如果您想使用 SURF 进行图像分类,例如数字识别,您需要将一组 SURF 描述符转换为单个向量。一种方法是使用 bag-of-features approach