如何将HOG特征添加到矩阵(matlab) [英] How to add HOG features into matrix (matlab)

查看:359
本文介绍了如何将HOG特征添加到矩阵(matlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提取图像文件夹的HOG特征之后,我想将所有这些结果添加到一个矩阵中。我怎么能这样做?这是我在matlab中的代码:

After extracting HOG features of folder of images, I want to add all this results in one matrix. How I can do this? this is my code in matlab:

training_female = 'E:\Training Set\Female Images';

% read all images with specified extention, its jpg in our case
filenames = dir(fullfile(training_female, '*.jpg'));

% count total number of photos present in that folder
total_images = numel(filenames);

for n = 1:total_images

% Specify images names with full path and extension    
full_name= fullfile(training_female, filenames(n).name);

% Read images
training_images = imread(full_name);
[featureVector, hogVisualization] = extractHOGFeatures(training_images);
figure (n)

    % Show all images
    imshow(training_images); hold on;                  
    plot(hogVisualization);
end


推荐答案

href =http://www.mathworks.com/help/vision/ref/extracthogfeatures.html =nofollow>文档,调用 extractHOGFeatures 给定输入图像计算 1 x N 向量。因为计算输出大小可能有点麻烦,这也取决于您为HOG检测器设置的参数,最好首先创建一个空矩阵,并在每次迭代时动态连接这些特征。通常,为了性能,您可以预先分配一个矩阵,如果你想在迭代的基础上填充元素。不这样做会给予轻微的性能,但它是最适应给你的情况。你可能想要调整HOG参数,如果我们这样做的动态方式,这消除了头痛的确定矩阵的总大小应该是什么。

By looking at the documentation, calling extractHOGFeatures computes a 1 x N vector given an input image. Because it can be a bit cumbersome to calculate what the output size of this may be, which also depends on what parameters you set up for the HOG detector, it's best to first create an empty matrix and dynamically concatenate the features at each iteration. Usually for performance you pre-allocate a matrix if you want to populate the elements on an iterative basis. Not doing it this way gives a slight ding in performance, but it's the most adaptable given your situation. You may want to adjust the HOG parameters and if we do it the dynamic way, that removes the headache of determining what the total size of the matrix should be.

这样的东西。我已将%//新标记放置在我已修改您的代码的位置:

So do something like this. I've placed %//New tags where I've modified your code:

training_female = 'E:\Training Set\Female Images';

% read all images with specified extention, its jpg in our case
filenames = dir(fullfile(training_female, '*.jpg'));

% count total number of photos present in that folder
total_images = numel(filenames);

featureMatrix = []; %// New - Declare feature matrix

for n = 1:total_images

    % Specify images names with full path and extension    
    full_name= fullfile(training_female, filenames(n).name);

    % Read images
    training_images = imread(full_name);
    [featureVector, hogVisualization] = extractHOGFeatures(training_images);

    %// New - Add feature vector to matrix
    featureMatrix = [featureMatrix; featureVector];
    figure(n);

    % Show all images
    imshow(training_images); hold on;                  
    plot(hogVisualization);
end

featureMatrix 您的HOG功能,其中每行是为每个图像。因此,对于特定图片 i ,您可以通过以下方式确定HOG特征:

featureMatrix will contain your HOG features where each row is for each image. Therefore, for a particular image i, you can determine the HOG features by:

feature = featureMatrix(i,:);



Caveat



上述代码假设您的目录中的所有图片大小相同。如果它们不是,那么每个HOG调用的输出向量大小将是不同的。如果是这样,您将需要一个单元格数组来适应不同的大小。

Caveat

I need to mention that the above code assumes that all images in your directory are the same size. If they're not, then the output vector size for each HOG call is going to be different. If that's the case, you'll want to have a cell array to adapt for the different sizes.

因此,做这样的事情:

training_female = 'E:\Training Set\Female Images';

% read all images with specified extention, its jpg in our case
filenames = dir(fullfile(training_female, '*.jpg'));

% count total number of photos present in that folder
total_images = numel(filenames);

featureMatrix = cell(1,total_images); %// New - Declare feature matrix

for n = 1:total_images

    % Specify images names with full path and extension    
    full_name= fullfile(training_female, filenames(n).name);

    % Read images
    training_images = imread(full_name);
    [featureVector, hogVisualization] = extractHOGFeatures(training_images);

    %// New - Add feature vector to matrix
    featureMatrix{n} = featureVector;
    figure(n);

    % Show all images
    imshow(training_images); hold on;                  
    plot(hogVisualization);
end

要访问特定图片的功能或图片 i ,do:

To access a particular image's features, or image i, do:

feature = featureMatrix{i};

这篇关于如何将HOG特征添加到矩阵(matlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆