How to spearate the output of vl_hog() into 6*6*31 blocks and use reshape() to convert every block to a row vector?

1 view (last 30 days)
How to spearate the output of vl_hog() into 6*6*31 blocks,
use reshape() to convert every block to a row vector,
save each vector to features_neg, and increase idx by 1
in the following code: check if do that correctly :
% Starter code prepared by James Hays, Brown University
% This function should return negative training examples (non-faces) from
% any images in 'non_face_scn_path'. Images should be converted to
% grayscale, because the positive training data is only available in
% grayscale. For best performance, you should sample random negative
% examples at multiple scales.
function features_neg = get_random_negative_features(non_face_scn_path, feature_params, num_samples)
% 'non_face_scn_path' is a string. This directory contains many images
% which have no faces in them.
% 'feature_params' is a struct, with fields
% feature_params.template_size (probably 36), the number of pixels
% spanned by each train / test template and
% feature_params.hog_cell_size (default 6), the number of pixels in each
% HoG cell. template size should be evenly divisible by hog_cell_size.
% Smaller HoG cell sizes tend to work better, but they make things
% slower because the feature dimensionality increases and more
% importantly the step size of the classifier decreases at test time.
% 'num_samples' is the number of random negatives to be mined, it's not
% important for the function to find exactly 'num_samples' non-face
% features, e.g. you might try to sample some number from each image, but
% some images might be too small to find enough.
% 'features_neg' is N by D matrix where N is the number of non-faces and D
% is the template dimensionality, which would be
% (feature_params.template_size / feature_params.hog_cell_size)^2 * 31
% if you're using the default vl_hog parameters
% Useful functions:
% vl_hog, HOG = VL_HOG(IM, CELLSIZE)
% http://www.vlfeat.org/matlab/vl_hog.html (API)
% http://www.vlfeat.org/overview/hog.html (Tutorial)
% rgb2gray
image_files = dir(fullfile(non_face_scn_path, '*.jpg'));
num_images = length(image_files);
% placeholder to be deleted
features_neg = rand(100, (feature_params.template_size / feature_params.hog_cell_size)^2 * 31);
step=feature_params.hog_cell_size;
idx=0;
for i=1:num_images
im=imread([non_face_scn_path '/' image_files(i).name]);
%%%%% please follow the steps below to compute HOG features for each image.
%%%%% 1. use single() function to convert input image to SINGLE class;
%%%%% 2. call vl_hog() function, two parameters: one is the image, the
%%%%% other is the feature_parames.hog_cell_size;
%%%%% Your code here!
im=single(im);
hog = vl_hog(im, feature_parames.hog_cell_size, 'verbose');
for m=1:step:size(im,1)
for n=1:step:size(im,2)
%%%%% spearate the output of vl_hog() into 6*6*31 blocks,
%%%%% use reshape() to convert every block to a row vector,
%%%%% save each vector to features_neg, and increase idx by 1
%%%%% Your code here!
features_neg(idx,:)=reshape(hog, [1, 6*6*31]);
idx=idx+1
end
end
disp(['idex is: ' num2str(idx)]);
disp(['case is: ' num2str(i)]);
end
idx

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!