4

I have downloaded three different HoG codes. using the image of 64x128

1) using the matlab function:extractHOGFeatures,

[hog, vis] = extractHOGFeatures(img,'CellSize',[8 8]);

The size of hog is 3780.

How to calculate:

HOG feature length, N, is based on the image size and the function parameter values.

N = prod([BlocksPerImage, BlockSize, NumBins])
BlocksPerImage = floor((size(I)./CellSize – BlockSize)./(BlockSize – BlockOverlap) + 1)

2) the second HOG function is downloaded from here. Same image is used

H = hog( double(rgb2gray(img)), 8, 9 );

 %  I        - [mxn] color or grayscale input image (must have type double)
%  sBin     - [8] spatial bin size
%  oBin     - [9] number of orientation bins

The size of H is 3024

How to calculate:

H        - [m/sBin-2 n/sBin-2 oBin*4] computed hog features

3) HoG code from vl_feat.

cellSize = 8;
 hog = vl_hog(im2single(rgb2gray(img)), cellSize, 'verbose','variant', 'dalaltriggs') ;
vl_hog: image: [64 x 128 x 1]
vl_hog: descriptor: [8 x 16 x 36]
vl_hog: number of orientations: 9
vl_hog: bilinear orientation assignments: no
vl_hog: variant: DalalTriggs
vl_hog: input type: Image

the output is 4608.

Which one is correct?

Addee
  • 663
  • 10
  • 21

1 Answers1

4

All are correct. Thing is HOG feature extraction function default parameters vary with packages. (Eg - opencv, matlab, scikit-image etc). By parameters I mean, winsize, stride, blocksize, scale etc.

Usually HOG descriptor length is :

 Length = Number of Blocks x Cells in each Block x Number of Bins in each Cell

Since all are correct, which one you may use can be answered in many ways. You can experiment with different param values and choose the one that suits you. Since there is no fixed way to find right values, it would be helpful if you know how change in each parameters affect the result.

Cell-size : If you increase this, you may not capture small details.

Block-size : Again, large block with large cell size may not help you capture the small details. Also since large block means illumination variation can be more and due to gradient normalization step, lot of details will be lost. So choose accordingly.

Overlap/Stride: This again helps you capture more information about the image patch if you choose overlapping blocks. Usually it is set to half the blocksize.

You may have lot of information by choosing the values of the above params accordingly. But the descriptor length will become unnecessarily long.

Hope this helps :)

harshkn
  • 731
  • 6
  • 13
  • Thanks, Just one this more. I am using libSVM for the classification. I need to arrange my feature matrix for 256 images as: 256x3780 and label vector as: 256x1 ? – Addee May 05 '17 at 00:28
  • 1
    Yes, that is what you need to do. If you think my answer solved your query, please accept this as an answer :) Good luck. – harshkn May 05 '17 at 03:32
  • can you please check this [link](http://stackoverflow.com/questions/44082270/hog-descriptor-is-rotation-invariant) – Addee May 20 '17 at 08:36