View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
HOG descriptor for Matlab

  • HOG(Im)Image descriptor based on Histogram of Orientated Gradients for gray-level images. This code
  • View all files
4.3 | 18 ratings Rate this file 141 Downloads (last 30 days) File Size: 1.85 KB File ID: #28689 Version: 1.1

HOG descriptor for Matlab


Oswaldo Ludwig (view profile)


11 Sep 2010 (Updated )

Image descriptor based on Histogram of Oriented Gradients for gray-level images

| Watch this File

File Information

This code is simple and commented, what enables the adjust of the HOG parameters. This code was developed for the work: O. Ludwig, D. Delgado, V. Goncalves, and U. Nunes, 'Trainable Classifier-Fusion Schemes: An Application To Pedestrian Detection,' In: 12th International IEEE Conference On Intelligent Transportation Systems, 2009, St. Louis, 2009. V. 1. P. 432-437. In case of publication with this code, please cite the paper above.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (37)
03 Nov 2016 Gerardo Ahumada


01 May 2016 Anvesha A Amaravati

19 Mar 2016 Juan Sebastian Quiroga Taborda

Hi.. Very skilled that code.
Would u mind telling me what I should add for recognizing a face with ur code. I ran it and it works perfectly but when I give it a face, it just displays an image with noise and other image with the contorn.
Thanks in Avance.

03 Sep 2015 Paula Marti


Comment only

i need help to make the code for
combining Food Image Recognition by Using Bag-of-SURF Features and HOG Features

Comment only
19 May 2015 dhia jamaa

07 Apr 2015 Oswaldo Ludwig

Oswaldo Ludwig (view profile)

Thanks, Hongmou!

Comment only
06 Apr 2015 Hongmou Zhang

It is a really nice code, Oswaldo.

09 Mar 2015 supreetha

I'm getting error with the code as
Attempted to access v_angles(1); index out of bounds because numel(v_angles)=0.

Error in HOG (line 44)
if v_angles(k)<ang_lim

can I please know what is the error?

Comment only
04 May 2014 Hisham Sager

After taking the HOG of a whole image, and taking the HOG of a 32x32 section, comparing the same location from the whole image HOG and the 32x32 HOG they are not the same. Even in the areas in the middle of the image which are far from the borders.
What is the reason?

Comment only
31 Mar 2014 Akshay Gore

Akshay Gore (view profile)

04 Feb 2014 Izem

Izem (view profile)

I think the code proposed by @Aaron is very helpful

Comment only
28 May 2013 Pervukhina

04 May 2013 Chris McCormick

I noticed a bug in the histogram computation. Gradient vectors whose angle is equal to pi are being omitted from the histogram because you check for angle < angle_lim instead of angle <= angle_lim.

I also re-wrote the histogram computation to optimize it in a way similar to what was suggested in an earlier comment.

% Compute the bin index for every angle.
binIndeces = ceil((v_angles + pi) / binSize);

% For each bin
for (bin = 1:B)
% Get the magnitudes for all the pixels that belong in 'bin'.
magnitudes = v_magnit(binIndeces == bin);

% Add all of the magnitudes to 'bin'.
H2(bin) = H2(bin) + sum(magnitudes);

Comment only
14 Mar 2013 tamanna

@Oswaldo Ludwig sir, may i have your full paper coding ''Trainable Classifier-Fusion Schemes: An Application To Pedestrian Detection''

Comment only
24 Jan 2013 Oswaldo Ludwig

Oswaldo Ludwig (view profile)

Could you explain why it was adopted blockwise normalization? From the best of my knowledge, there is no mathematical foundation behind HOG descriptors, only good sense. This is my version, which was made available to be evaluated by the community. Go ahead, you should make the comparison with other algorithms in your case study (Science is not religion, feel free to doubt and inovate).

Comment only
24 Jan 2013 Lukas Tencer

Also you are doing normalization of the final vector, originally it supposed to be blockwise normalization, did you try that version? Why you decided for normalization only of final histogram.

Comment only
24 Jan 2013 Lukas Tencer

Should not be contribution of individual points to the histogram weighted according to gaussian centred in the middle of each cell?

07 Nov 2012 Algorithms Analyst

Can anyone help I am runiing this code but finding error?
Thanks inadvance

??? Input argument "Im" is undefined.

Error in ==> HOG at 11
[L,C]=size(Im); % L num of lines ; C num of columns


sir,i run your code,i am getting the error

??? Input argument "Im" is undefined.

Error in ==> HOG at 11
[L,C]=size(Im); % L num of lines ; C num of columns

please help me to correct this.

19 Oct 2012 Raul

Raul (view profile)

09 Oct 2012 Alsam

Alsam (view profile)

28 Sep 2012 saif

saif (view profile)

Can we use this code for object NOT human?

If I want to classify objects such as coca-cola and ketchup, can I do this directly with this code, I mean to use these features?

Comment only
28 Sep 2012 Oswaldo Ludwig

Oswaldo Ludwig (view profile)

Raul, the number of features depends on the number of cells and histograms bins, see Section II-A of this paper:[113]2009ITSC09-129-FI.pdf

Comment only
28 Sep 2012 Raul

Raul (view profile)

I would like to know why the size of the HOG vector is the same for each image with different sizes.

Comment only
27 Sep 2012 Prabhu

Prabhu (view profile)

20 Sep 2012 Aaron

Aaron (view profile)

replace lines 42-47 with code below for 20x speed-up

idx = find(v_angles<ang_lim);
v_angles(idx) = 100;
H2(bin) = H2(bin) + sum(v_magnit(idx));

08 Jun 2012 Stathis Fotiadis

01 Jun 2012 Oswaldo Ludwig

Oswaldo Ludwig (view profile)

An application for human detection (Windows only) can be found in
The program is based on HOG descriptors for Matlab arranged in SRM-cascade, according to the methodology described in: O. Ludwig; “ Study on Non-parametric Methods for Fast Pattern Recognition with Emphasis on Neural Networks and Cascade Classifiers;” PhD Thesis, University of Coimbra, Coimbra, 2012. New images can be included in the folder "images" with the name "ped_XX". The algorithm was trained by using 18x36 gray-scale images from the Daimler Pedestrian Classification dataset. Double-click in detector_pkg.exe to install the program, then it is possible to run detector.exe.

Comment only
14 Mar 2012 Swan

Swan (view profile)

Hi,what is this section for?
if C==1
in what case, C==1?

Comment only
06 Jan 2012 Caelyn Low

27 Nov 2011 Aeris

Aeris (view profile)

Hi, do you have any example showing how the descriptor is applied to an 640x480 image?
And i don't really understand how does 2*pi/B = 360/9 => 20 degrees per bin? As i see it is equal to 40 degrees.

Please correct me if i were wrong, thanks.

Comment only
22 Nov 2011 Tom

Tom (view profile)

Hello. Why in this case is use y filter hy=-hx' and not hy=hx'?

Thank you for your answer in advance.


03 Oct 2011 David Lewis

17 Mar 2011 Oswaldo Ludwig

Oswaldo Ludwig (view profile)

Dear Luis, you're right, a revised version was submitted.

Comment only
16 Mar 2011 Luis Alejandro Fonseca Rodriguez

Hello, I have found a error in your HOG descriptor program, the magnitude is calculated wrong. You multiply when you should sum.

Comment only
04 Nov 2010 Oswaldo Ludwig

Oswaldo Ludwig (view profile)

We have achieved good result in object detection, regarding detection speed and accuracy, by combining this descriptor with NN trained by MMGDX, see:

Comment only
17 Mar 2011 1.1

A problem in the calculation of gradient norm was corrected

Contact us